From 18260f402b6be0cd4931f2b690106bba51f789b1 Mon Sep 17 00:00:00 2001 From: Valentin Torikian Date: Sun, 24 May 2015 17:51:37 +0200 Subject: [PATCH 1/4] Implemented PSR-4 autoloading --- .gitignore | 2 + bin/mar.php | 22 ++++++++++ composer.json | 43 ++++++++++++------- {classes => src/Option}/options.php | 2 +- {classes => src/Reporter}/reporter.php | 8 ++-- {classes => src/Scanner}/scanner.php | 4 +- .../tests => src/Tester/Type}/critical.php | 4 +- {classes/tests => src/Tester/Type}/nuance.php | 4 +- {classes => src/Tester}/tests.php | 6 +-- mar.php => src/mar.php | 28 +++--------- 10 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 bin/mar.php rename {classes => src/Option}/options.php (99%) rename {classes => src/Reporter}/reporter.php (97%) rename {classes => src/Scanner}/scanner.php (98%) rename {classes/tests => src/Tester/Type}/critical.php (99%) rename {classes/tests => src/Tester/Type}/nuance.php (98%) rename {classes => src/Tester}/tests.php (97%) rename mar.php => src/mar.php (85%) diff --git a/.gitignore b/.gitignore index 2991481..b1d0fca 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ *.sublime-workspace /reports/*.txt /reports/*.md +vendor +composer.lock diff --git a/bin/mar.php b/bin/mar.php new file mode 100644 index 0000000..7bb2519 --- /dev/null +++ b/bin/mar.php @@ -0,0 +1,22 @@ +#!/usr/bin/env 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" + } + } } diff --git a/classes/options.php b/src/Option/options.php similarity index 99% rename from classes/options.php rename to src/Option/options.php index e1c1332..cc40ba2 100644 --- a/classes/options.php +++ b/src/Option/options.php @@ -8,7 +8,7 @@ * @link https://github.com/Alexia/php7mar */ -namespace mar; +namespace Alexia\Mar\Option; class options { /** diff --git a/classes/reporter.php b/src/Reporter/reporter.php similarity index 97% rename from classes/reporter.php rename to src/Reporter/reporter.php index d593ee2..1ac3ea2 100644 --- a/classes/reporter.php +++ b/src/Reporter/reporter.php @@ -8,7 +8,9 @@ * @link https://github.com/Alexia/php7mar */ -namespace mar; +namespace Alexia\Mar\Reporter; + +use Alexia\Mar\mar; class reporter { /** @@ -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 { @@ -171,4 +173,4 @@ public function onShutdown() { fclose($this->file); } } -?> \ No newline at end of file +?> diff --git a/classes/scanner.php b/src/Scanner/scanner.php similarity index 98% rename from classes/scanner.php rename to src/Scanner/scanner.php index 27dfe33..22526cb 100644 --- a/classes/scanner.php +++ b/src/Scanner/scanner.php @@ -8,7 +8,7 @@ * @link https://github.com/Alexia/php7mar */ -namespace mar; +namespace Alexia\Mar\Scanner; class scanner { /** @@ -101,4 +101,4 @@ public function getCurrentFilePath() { return current($this->files); } } -?> \ No newline at end of file +?> diff --git a/classes/tests/critical.php b/src/Tester/Type/critical.php similarity index 99% rename from classes/tests/critical.php rename to src/Tester/Type/critical.php index e60f9d5..0c52ce4 100644 --- a/classes/tests/critical.php +++ b/src/Tester/Type/critical.php @@ -8,7 +8,7 @@ * @link https://github.com/Alexia/php7mar */ -namespace mar\tests; +namespace Alexia\Mar\Tester\Type; class critical { /** @@ -117,4 +117,4 @@ public function _deprecatedFunctions($line) { return false; } } -?> \ No newline at end of file +?> diff --git a/classes/tests/nuance.php b/src/Tester/Type/nuance.php similarity index 98% rename from classes/tests/nuance.php rename to src/Tester/Type/nuance.php index e9dda99..d87bb68 100644 --- a/classes/tests/nuance.php +++ b/src/Tester/Type/nuance.php @@ -8,7 +8,7 @@ * @link https://github.com/Alexia/php7mar */ -namespace mar\tests; +namespace Alexia\Mar\Tester\Type; class nuance { /** @@ -164,4 +164,4 @@ public function _unicode($line) { return false; } } -?> \ No newline at end of file +?> diff --git a/classes/tests.php b/src/Tester/tests.php similarity index 97% rename from classes/tests.php rename to src/Tester/tests.php index 548781b..a54d052 100644 --- a/classes/tests.php +++ b/src/Tester/tests.php @@ -9,7 +9,7 @@ * @link https://github.com/Alexia/php7mar */ -namespace mar; +namespace Alexia\Mar\Tester; class tests { /** @@ -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; } /** @@ -161,4 +161,4 @@ public function checkSyntax($filePath) { return $syntax; } } -?> \ No newline at end of file +?> diff --git a/mar.php b/src/mar.php similarity index 85% rename from mar.php rename to src/mar.php index 89ebbf5..a82b2f0 100644 --- a/mar.php +++ b/src/mar.php @@ -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 * @@ -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(); @@ -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. * @@ -180,5 +167,4 @@ static public function getRealPath($path) { return false; } } -$mar = new \mar\main(); ?> From 7420161e53c6b379871ea62ccd793efca33f922e Mon Sep 17 00:00:00 2001 From: Valentin Torikian Date: Sun, 24 May 2015 17:57:45 +0200 Subject: [PATCH 2/4] Fixed a bug with the 'r' option. --- src/Reporter/reporter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Reporter/reporter.php b/src/Reporter/reporter.php index 1ac3ea2..1aa11f6 100644 --- a/src/Reporter/reporter.php +++ b/src/Reporter/reporter.php @@ -75,9 +75,9 @@ public function __construct($projectPath, $reportFolder = null) { if ($reportFolder !== false) { $this->reportFolder = $reportFolder; } else { - $this->reportFolder = PHP7MAR_DIR.DIRECTORY_SEPARATOR.'reports'.DIRECTORY_SEPARATOR; + $this->reportFolder = PHP7MAR_DIR.'reports'.DIRECTORY_SEPARATOR; } - $this->fullFilePath = $this->reportFolder.date('Y-m-d H:i:s ').basename($this->projectPath, '.php').".md"; + $this->fullFilePath = $this->reportFolder.DIRECTORY_SEPARATOR.date('Y-m-d H:i:s ').basename($this->projectPath, '.php').".md"; $this->file = fopen($this->fullFilePath, 'w+'); register_shutdown_function([$this, 'onShutdown']); From 63b45b4f5c75691608160db18ed3821c6bc2eb7c Mon Sep 17 00:00:00 2001 From: Valentin Torikian Date: Sun, 24 May 2015 18:15:39 +0200 Subject: [PATCH 3/4] updated doc to reflect the new directory hierarchy --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 453e107..7e04fd4 100644 --- a/README.md +++ b/README.md @@ -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** @@ -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" \ No newline at end of file +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" From 47181754ee45456bfd843f4f64f7a52dcd47e9a9 Mon Sep 17 00:00:00 2001 From: Valentin Torikian Date: Sun, 24 May 2015 18:37:11 +0200 Subject: [PATCH 4/4] Revert "Fixed a bug with the 'r' option." This reverts commit 7420161e53c6b379871ea62ccd793efca33f922e. --- src/Reporter/reporter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Reporter/reporter.php b/src/Reporter/reporter.php index 1aa11f6..1ac3ea2 100644 --- a/src/Reporter/reporter.php +++ b/src/Reporter/reporter.php @@ -75,9 +75,9 @@ public function __construct($projectPath, $reportFolder = null) { if ($reportFolder !== false) { $this->reportFolder = $reportFolder; } else { - $this->reportFolder = PHP7MAR_DIR.'reports'.DIRECTORY_SEPARATOR; + $this->reportFolder = PHP7MAR_DIR.DIRECTORY_SEPARATOR.'reports'.DIRECTORY_SEPARATOR; } - $this->fullFilePath = $this->reportFolder.DIRECTORY_SEPARATOR.date('Y-m-d H:i:s ').basename($this->projectPath, '.php').".md"; + $this->fullFilePath = $this->reportFolder.date('Y-m-d H:i:s ').basename($this->projectPath, '.php').".md"; $this->file = fopen($this->fullFilePath, 'w+'); register_shutdown_function([$this, 'onShutdown']);