Skip to content
This repository was archived by the owner on Feb 27, 2020. It is now read-only.

Implement psr4 #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
*.sublime-workspace
/reports/*.txt
/reports/*.md
vendor
composer.lock
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ First, start by downloading or cloning this repository. It does not need to be

To begin, type on the command line:

php mar.php
php bin/mar.php

This will produce a list of available arguments and switches.

Typical usage would appear as:

php mar.php -f="/path/to/file/example.php"
php bin/mar.php -f="/path/to/file/example.php"

Or:

php mar.php -f="/path/to/folder/example/"
php bin/mar.php -f="/path/to/folder/example/"

This would run against the example file or folder and save the resulting report into a reports folder inside the php7mar folder. When referencing the file or folder to run against it is recommend to use a fully qualified path. Relative paths are supported, but will be relative to the location of the php7mar folder.

Give a try, use the included `testcases.php` to generate a report:

php mar.php -f="testcases.php"
php bin/mar.php -f="testcases.php"

##Available Options:
**-f**
Expand Down Expand Up @@ -77,4 +77,4 @@ Critical tests look for issues that will cause broken code, compilation errors,
Nuance tests look for issues that might cause silent underisable code behavior. These tests can report many false positives as they can not determine the intent of the code being checked.

##Syntax
A basic command line based syntax checker that checks all files for standard syntax issues. This is useful for double checking work after making many mass find and replace operations. Please note that syntax checking adds a significant increase to processing time especially for large code bases. To run without syntax checking use the -t option and omit syntax; -t="critical,nuance"
A basic command line based syntax checker that checks all files for standard syntax issues. This is useful for double checking work after making many mass find and replace operations. Please note that syntax checking adds a significant increase to processing time especially for large code bases. To run without syntax checking use the -t option and omit syntax; -t="critical,nuance"
22 changes: 22 additions & 0 deletions bin/mar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env php
<?php

if (is_file($autoload = getcwd() . '/vendor/autoload.php')) {
require $autoload;
} elseif (is_file($autoload = getcwd() . '/../../autoload.php')) {
require $autoload;
}
if (is_file($autoload = __DIR__ . '/../vendor/autoload.php')) {
require($autoload);
} elseif (is_file($autoload = __DIR__ . '/../../../autoload.php')) {
require($autoload);
} else {
fwrite(STDERR,
'You must set up the project dependencies, run the following commands:' . PHP_EOL .
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
exit(1);
}
$app = new \Alexia\Mar\mar();

43 changes: 27 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
{
"name": "alexia/php7mar",
"type": "project",
"description": "PHP 7 MAR, or just \"php7mar\", is a command line utility to generate reports on existing PHP 5 code to assist developers in porting their code quickly to PHP 7.",
"keywords": ["php7", "php5", "migration", "porting"],
"homepage": "https://github.com/Alexia/php7mar",
"license": "GPL-3.0",
"authors": [
{
"name": "Alexia E. Smith",
"email": "washuu@gmail.com",
"role": "Developer"
}
],
"require": {
"php": ">=5.4.0"
}
"name": "alexia/php7mar",
"type": "project",
"description": "PHP 7 MAR, or just \"php7mar\", is a command line utility to generate reports on existing PHP 5 code to assist developers in porting their code quickly to PHP 7.",
"keywords": [
"php7",
"php5",
"migration",
"porting"
],
"homepage": "https://github.com/Alexia/php7mar",
"license": "GPL-3.0",
"authors": [
{
"name": "Alexia E. Smith",
"email": "washuu@gmail.com",
"role": "Developer"
}
],
"require": {
"php": ">=5.4.0"
},

"autoload": {
"psr-4": {
"Alexia\\Mar\\": "src"
}
}
}
2 changes: 1 addition & 1 deletion classes/options.php → src/Option/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/Alexia/php7mar
*/

namespace mar;
namespace Alexia\Mar\Option;

class options {
/**
Expand Down
8 changes: 5 additions & 3 deletions classes/reporter.php → src/Reporter/reporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
* @link https://github.com/Alexia/php7mar
*/

namespace mar;
namespace Alexia\Mar\Reporter;

use Alexia\Mar\mar;

class reporter {
/**
Expand Down Expand Up @@ -69,7 +71,7 @@ public function __construct($projectPath, $reportFolder = null) {
}
$this->projectPath = $projectPath;

$reportFolder = main::getRealPath($reportFolder);
$reportFolder = mar::getRealPath($reportFolder);
if ($reportFolder !== false) {
$this->reportFolder = $reportFolder;
} else {
Expand Down Expand Up @@ -171,4 +173,4 @@ public function onShutdown() {
fclose($this->file);
}
}
?>
?>
4 changes: 2 additions & 2 deletions classes/scanner.php → src/Scanner/scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/Alexia/php7mar
*/

namespace mar;
namespace Alexia\Mar\Scanner;

class scanner {
/**
Expand Down Expand Up @@ -101,4 +101,4 @@ public function getCurrentFilePath() {
return current($this->files);
}
}
?>
?>
4 changes: 2 additions & 2 deletions classes/tests/critical.php → src/Tester/Type/critical.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/Alexia/php7mar
*/

namespace mar\tests;
namespace Alexia\Mar\Tester\Type;

class critical {
/**
Expand Down Expand Up @@ -117,4 +117,4 @@ public function _deprecatedFunctions($line) {
return false;
}
}
?>
?>
4 changes: 2 additions & 2 deletions classes/tests/nuance.php → src/Tester/Type/nuance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://github.com/Alexia/php7mar
*/

namespace mar\tests;
namespace Alexia\Mar\Tester\Type;

class nuance {
/**
Expand Down Expand Up @@ -164,4 +164,4 @@ public function _unicode($line) {
return false;
}
}
?>
?>
6 changes: 3 additions & 3 deletions classes/tests.php → src/Tester/tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @link https://github.com/Alexia/php7mar
*/

namespace mar;
namespace Alexia\Mar\Tester;

class tests {
/**
Expand Down Expand Up @@ -74,7 +74,7 @@ public function __construct($testTypes = []) {
* @return string Test Class Name
*/
public function getTestClassName($testType) {
return "mar\\tests\\".$testType;
return "Alexia\\Mar\\Tester\\Type\\".$testType;
}

/**
Expand Down Expand Up @@ -161,4 +161,4 @@ public function checkSyntax($filePath) {
return $syntax;
}
}
?>
?>
31 changes: 9 additions & 22 deletions mar.php → src/mar.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
* @link https://github.com/Alexia/php7mar
*/

namespace mar;
namespace Alexia\Mar;

class main {
use Alexia\Mar\Option\options;
use Alexia\Mar\Reporter\reporter;
use Alexia\Mar\Scanner\scanner;
use Alexia\Mar\Tester\tests;

class mar {
/**
* Project File or Path
*
Expand Down Expand Up @@ -55,7 +60,6 @@ class main {
public function __construct() {
define('PHP7MAR_DIR', __DIR__);
define('PHP7MAR_VERSION', '0.0.1');
spl_autoload_register([$this, 'autoloader'], true, false);

//Setup command line options/switches.
$this->options = new options();
Expand Down Expand Up @@ -144,23 +148,6 @@ private function run() {
$this->reporter->add("Processed {$totalLines} lines contained in {$totalFiles} files.", 0, 1);
}

/**
* Autoloader
*
* @access public
* @param string Class name to load automatically.
* @return void
*/
static public function autoloader($className) {
$className = str_replace('mar\\', '', $className);
$file = PHP7MAR_DIR.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $className).'.php';
if (is_file($file)) {
require_once($file);
} else {
throw new \Exception(__CLASS__.": Class file for {$className} not found at {$file}.");
}
}

/**
* Get a full real path name to a given path.
*
Expand All @@ -180,5 +167,5 @@ static public function getRealPath($path) {
return false;
}
}
$mar = new \mar\main();
?>

?>