From ebd6a7e82f9bf18ffe331aaec6a528629f1d5ca1 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 28 Jan 2019 06:41:03 +0000 Subject: [PATCH 01/16] Check for named constants Eg remove $six = 6 or $week = 7 These sorts of numbers are still magic, fixes #83 --- README.md | 4 +- src/Console/Command.php | 8 +++ src/Console/Option.php | 28 +++++++++ src/Language.php | 12 ++++ src/Languages/En.php | 105 ++++++++++++++++++++++++++++++++ src/Visitor/DetectorVisitor.php | 42 +++++++++++++ tests/DetectorTest.php | 30 +++++++++ tests/files/check_names.php | 11 ++++ 8 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 src/Language.php create mode 100644 src/Languages/En.php create mode 100644 tests/files/check_names.php diff --git a/README.md b/README.md index 655ca99..ab5e071 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,9 @@ The ``--allow-array-mapping`` option allow keys as strings when using "array" ex The ``--xml-output`` option will generate an report in an Xml format to the path specified by the option. -The ``--whitelist`` option will only process the files listed in the file specified. This is useful for incremental anaysis. +The ``--whitelist`` option will only process the files listed in the file specified. This is useful for incremental analysis. + +The ``--check-naming`` option will check for names for numbers being used, eg `$six = 6`; You also need to pass in a csv of supported languages you wish to check (e.g. en) **By default it analyses conditions, return statements, and switch cases.** diff --git a/src/Console/Command.php b/src/Console/Command.php index e59c2b4..427c77e 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -138,6 +138,13 @@ protected function configure(): void 'Link to a file containing filenames to search', '' ) + ->addOption( + 'check-naming', + null, + InputOption::VALUE_REQUIRED, + 'Check the names of variables to ensure they are not numeric', + '' + ) ; } @@ -211,6 +218,7 @@ private function createOption(InputInterface $input): Option $option = new Option; $option->setIgnoreNumbers(array_map([$this, 'castToNumber'], $this->getCSVOption($input, 'ignore-numbers'))); $option->setIgnoreFuncs($this->getCSVOption($input, 'ignore-funcs')); + $option->setCheckNaming($this->getCSVOption($input, 'check-naming')); $option->setIncludeStrings($input->getOption('strings')); $option->setIncludeNumericStrings($input->getOption('include-numeric-string')); $option->setIgnoreStrings($this->getCSVOption($input, 'ignore-strings')); diff --git a/src/Console/Option.php b/src/Console/Option.php index 11b3963..2b00951 100644 --- a/src/Console/Option.php +++ b/src/Console/Option.php @@ -3,6 +3,7 @@ namespace Povils\PHPMND\Console; use Povils\PHPMND\Extension\Extension; +use Povils\PHPMND\Language; /** * @package Povils\PHPMND\Console @@ -49,6 +50,11 @@ class Option */ private $allowArrayMapping = false; + /** + * @var array + */ + private $checkNaming = []; + public function setExtensions(array $extensions) { $this->extensions = $extensions; @@ -128,4 +134,26 @@ public function setAllowArrayMapping(?bool $allowArrayMapping) { $this->allowArrayMapping = $allowArrayMapping; } + + /** + * @return Language[] + */ + public function checkNaming(): array + { + return $this->checkNaming; + } + + public function setCheckNaming(array $checkNaming) + { + $languages = []; + foreach ($checkNaming as $language) { + $language = ucfirst($language); + $className = '\Povils\PHPMND\Languages\\' . $language; + + if (class_exists($className)) { + $languages[] = new $className(); + } + } + $this->checkNaming = $languages; + } } diff --git a/src/Language.php b/src/Language.php new file mode 100644 index 0000000..a1b5e8b --- /dev/null +++ b/src/Language.php @@ -0,0 +1,12 @@ + [ + 'half', + ], + 3 => [ + 'third', + ], + 7 => [ + 'week', + ], + 10 => [ + 'tenth', + 'decile', + ], + 24 => [ + 'hours', + ], + 28 => [ + 'February', + ], + 60 => [ + 'second', + 'minute', + ], + 100 => [ + 'percent', + 'centile' + ], + ]; + + protected $numberMapping = [ + 'zero', + 'one', + 'two', + 'three', + 'four', + 'five', + 'six', + 'seven', + 'eight', + 'nine', + 'ten', + 'eleven', + 'twelve', + 'thirteen', + 'fourteen', + 'fifteen', + 'sixteen', + 'seventeen', + 'eighteen', + 'nineteen', + 'twenty', + 30 => 'thirty', + 40 => 'forty', + 50 => 'fifty', + 60 => 'sixty', + 70 => 'seventy', + 80 => 'eighty', + 90 => 'ninety', + 100 => 'hundred', + 1000 => 'thousand', + 1000000 => 'million', + ]; + + public function parse(int $number): array + { + + end($this->numberMapping); + $final = $this->specialNumbers[$number] ?? []; + + if ($number < 0) { + $final [] = 'minus'; + $final [] = 'negative'; + + $number = -$number; + } + + while (prev($this->numberMapping) !== false && $number > 0) { + $key = key($this->numberMapping); + + if ($number < $key) { + continue; + } + $multiple = 1; + + if ($key * 2 < $number && $key > 0) { + $multiple = floor($number / $key); + + $final = array_merge($final, $this->parse($multiple)); + } + + $final[] = current($this->numberMapping); + $number -= $key * $multiple; + } + + return $final; + } +} diff --git a/src/Visitor/DetectorVisitor.php b/src/Visitor/DetectorVisitor.php index 6971968..ce105a8 100644 --- a/src/Visitor/DetectorVisitor.php +++ b/src/Visitor/DetectorVisitor.php @@ -44,12 +44,28 @@ public function __construct(FileReport $fileReport, Option $option) public function enterNode(Node $node): ?int { if ($this->isIgnoreableConst($node)) { + if ($this->checkNameContainsLanguage( + $node->name->name, + $node->value->value ?? 0 + )) { + $this->fileReport->addEntry($node->getLine(), $node->value->value); + } + return NodeTraverser::DONT_TRAVERSE_CHILDREN; } + if ($this->isNumber($node) || $this->isString($node)) { /** @var LNumber|DNumber|String_ $scalar */ $scalar = $node; + + if ($this->checkNameContainsLanguage( + $node->getAttribute('parent')->var->name ?? '', + $node->value + )) { + $this->fileReport->addEntry($node->getLine(), $scalar->value); + } + if ($this->hasSign($node)) { $node = $node->getAttribute('parent'); if ($this->isMinus($node)) { @@ -119,4 +135,30 @@ private function isValidNumeric(Node $node): bool is_numeric($node->value) && false === $this->ignoreString($node); } + + /** + * @param string $name + * @param string|int $value + * @return bool + */ + private function checkNameContainsLanguage(string $name, $value): bool + { + foreach ($this->option->checkNaming() as $language) { + $generatedNumbers = $language->parse($value); + + $regex = '/^'; + foreach ($generatedNumbers as $word) { + $regex .= "(?:{$word}[\s_-]*)?"; + } + + $regex .= '$/i'; + $match = preg_match($regex, $name); + + if ($match) { + return true; + } + } + + return false; + } } diff --git a/tests/DetectorTest.php b/tests/DetectorTest.php index d169bf9..e3ac6fc 100644 --- a/tests/DetectorTest.php +++ b/tests/DetectorTest.php @@ -277,6 +277,36 @@ public function testDetectReadingNumber(): void ); } + public function testNamesCorrectlyFound() + { + + $option = $this->createOption(); + $option->setCheckNaming(['en']); + $detector = $this->createDetector($option); + + $fileReport = $detector->detect(FileReportTest::getTestFile('check_names')); + + $this->assertSame( + [ + [ + 'line' => 4, + 'value' => 27, + ], + [ + 'line' => 8, + 'value' => 98, + ], + [ + 'line' => 9, + 'value' => 7, + ], + + ], + $fileReport->getEntries() + ); + + } + public function testAllowArrayMappingWithArrayExtension(): void { $option = $this->createOption(); diff --git a/tests/files/check_names.php b/tests/files/check_names.php new file mode 100644 index 0000000..8cdd5fa --- /dev/null +++ b/tests/files/check_names.php @@ -0,0 +1,11 @@ + Date: Mon, 28 Jan 2019 11:45:28 +0000 Subject: [PATCH 02/16] PSR-2 --- tests/DetectorTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/DetectorTest.php b/tests/DetectorTest.php index e3ac6fc..35c72c5 100644 --- a/tests/DetectorTest.php +++ b/tests/DetectorTest.php @@ -304,7 +304,6 @@ public function testNamesCorrectlyFound() ], $fileReport->getEntries() ); - } public function testAllowArrayMappingWithArrayExtension(): void From ee2fa2c70f071aac02b73778a6a611666102fb2e Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 28 Jan 2019 11:45:46 +0000 Subject: [PATCH 03/16] PSR-2 --- src/Language.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Language.php b/src/Language.php index a1b5e8b..203d99f 100644 --- a/src/Language.php +++ b/src/Language.php @@ -2,11 +2,10 @@ namespace Povils\PHPMND; - interface Language { /* * Returns an array of words which */ public function parse(int $number): array; -} \ No newline at end of file +} From 711f66f76ed76d71afdf9984e14e219b1765d58e Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 28 Jan 2019 22:48:01 +0000 Subject: [PATCH 04/16] Minor fix --- src/Languages/En.php | 4 ++-- src/Visitor/DetectorVisitor.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Languages/En.php b/src/Languages/En.php index 6695982..f6f7983 100644 --- a/src/Languages/En.php +++ b/src/Languages/En.php @@ -82,7 +82,7 @@ public function parse(int $number): array $number = -$number; } - while (prev($this->numberMapping) !== false && $number > 0) { + do { $key = key($this->numberMapping); if ($number < $key) { @@ -98,7 +98,7 @@ public function parse(int $number): array $final[] = current($this->numberMapping); $number -= $key * $multiple; - } + } while (prev($this->numberMapping) !== false && $number > 0); return $final; } diff --git a/src/Visitor/DetectorVisitor.php b/src/Visitor/DetectorVisitor.php index ce105a8..539f76f 100644 --- a/src/Visitor/DetectorVisitor.php +++ b/src/Visitor/DetectorVisitor.php @@ -146,15 +146,15 @@ private function checkNameContainsLanguage(string $name, $value): bool foreach ($this->option->checkNaming() as $language) { $generatedNumbers = $language->parse($value); - $regex = '/^'; + $regex = '/(?'; foreach ($generatedNumbers as $word) { $regex .= "(?:{$word}[\s_-]*)?"; } - $regex .= '$/i'; - $match = preg_match($regex, $name); + $regex .= ')/i'; + preg_match($regex, $name, $matches); - if ($match) { + if (strlen($matches['name']) > 0) { return true; } } From 2553540ebcd1f0de26cb17d7bc03f6edcc544121 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 28 Jan 2019 23:09:07 +0000 Subject: [PATCH 05/16] debug failing build --- src/Languages/En.php | 2 +- tests/DetectorTest.php | 2 +- tests/files/{check_names.php => test_4.php} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename tests/files/{check_names.php => test_4.php} (100%) diff --git a/src/Languages/En.php b/src/Languages/En.php index f6f7983..4b41b5e 100644 --- a/src/Languages/En.php +++ b/src/Languages/En.php @@ -82,7 +82,7 @@ public function parse(int $number): array $number = -$number; } - do { + do { $key = key($this->numberMapping); if ($number < $key) { diff --git a/tests/DetectorTest.php b/tests/DetectorTest.php index 35c72c5..4bb2a92 100644 --- a/tests/DetectorTest.php +++ b/tests/DetectorTest.php @@ -284,7 +284,7 @@ public function testNamesCorrectlyFound() $option->setCheckNaming(['en']); $detector = $this->createDetector($option); - $fileReport = $detector->detect(FileReportTest::getTestFile('check_names')); + $fileReport = $detector->detect(FileReportTest::getTestFile('test_4')); $this->assertSame( [ diff --git a/tests/files/check_names.php b/tests/files/test_4.php similarity index 100% rename from tests/files/check_names.php rename to tests/files/test_4.php From a98593b323ebd1cd9d37be5ac0296882785de702 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Tue, 29 Jan 2019 16:58:49 +0000 Subject: [PATCH 06/16] remove magic number from test All tests should pass now --- tests/Console/CommandTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Console/CommandTest.php b/tests/Console/CommandTest.php index a453d10..0886209 100644 --- a/tests/Console/CommandTest.php +++ b/tests/Console/CommandTest.php @@ -36,12 +36,18 @@ public function testExecuteWithHintOption(): void { $input = $this->createInput('assign', null, true, true); $output = $this->createOutput(); + $textOutput = ''; $output - ->expects($this->at(9)) ->method('writeln') - ->with('Suggestions:'); + ->will($this->returnCallback( + function($string) use (&$textOutput) { + $textOutput .= $string; + } + )); $this->execute([$input, $output]); + + $this->assertStringContainsString('Suggestions:', $textOutput); } private function execute(array $args): int From 340a32ba8cf1108d867eb2c63afadee465c8c144 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Tue, 29 Jan 2019 17:04:36 +0000 Subject: [PATCH 07/16] Rename file back --- tests/Console/CommandTest.php | 2 +- tests/DetectorTest.php | 2 +- tests/files/{test_4.php => check_naming.php} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename tests/files/{test_4.php => check_naming.php} (100%) diff --git a/tests/Console/CommandTest.php b/tests/Console/CommandTest.php index 0886209..5181d20 100644 --- a/tests/Console/CommandTest.php +++ b/tests/Console/CommandTest.php @@ -40,7 +40,7 @@ public function testExecuteWithHintOption(): void $output ->method('writeln') ->will($this->returnCallback( - function($string) use (&$textOutput) { + function ($string) use (&$textOutput) { $textOutput .= $string; } )); diff --git a/tests/DetectorTest.php b/tests/DetectorTest.php index 4bb2a92..fb32082 100644 --- a/tests/DetectorTest.php +++ b/tests/DetectorTest.php @@ -284,7 +284,7 @@ public function testNamesCorrectlyFound() $option->setCheckNaming(['en']); $detector = $this->createDetector($option); - $fileReport = $detector->detect(FileReportTest::getTestFile('test_4')); + $fileReport = $detector->detect(FileReportTest::getTestFile('check_naming')); $this->assertSame( [ diff --git a/tests/files/test_4.php b/tests/files/check_naming.php similarity index 100% rename from tests/files/test_4.php rename to tests/files/check_naming.php From b0072aa3a25d279f3cd9052cc057f57536e91ac7 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Tue, 29 Jan 2019 17:06:54 +0000 Subject: [PATCH 08/16] Support older phpunit versions --- tests/Console/CommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Console/CommandTest.php b/tests/Console/CommandTest.php index 5181d20..8ff576d 100644 --- a/tests/Console/CommandTest.php +++ b/tests/Console/CommandTest.php @@ -47,7 +47,7 @@ function ($string) use (&$textOutput) { $this->execute([$input, $output]); - $this->assertStringContainsString('Suggestions:', $textOutput); + $this->assertTrue(strpos($textOutput, 'Suggestions:') > 1); } private function execute(array $args): int From 8f1dff8b8dc1a734997403a537143b604d14a910 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Tue, 5 Mar 2019 21:00:37 +0000 Subject: [PATCH 09/16] Fix for #92 --- src/Visitor/DetectorVisitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Visitor/DetectorVisitor.php b/src/Visitor/DetectorVisitor.php index db67e24..01a484d 100644 --- a/src/Visitor/DetectorVisitor.php +++ b/src/Visitor/DetectorVisitor.php @@ -56,7 +56,7 @@ public function enterNode(Node $node): ?int /** @var LNumber|DNumber|String_ $scalar */ $scalar = $node; - if ($this->hasSign($scalar)) { + if ($this->hasSign($scalar) && $this->isNumber($scalar)) { $node = $scalar->getAttribute('parent'); if ($this->isMinus($node)) { $scalar->value = -$scalar->value; From 9c676df0cf803db0bda8cf26c8ad04420782f505 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Thu, 7 Mar 2019 05:43:20 +0000 Subject: [PATCH 10/16] actual fix --- src/Visitor/DetectorVisitor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Visitor/DetectorVisitor.php b/src/Visitor/DetectorVisitor.php index 01a484d..c003c8b 100644 --- a/src/Visitor/DetectorVisitor.php +++ b/src/Visitor/DetectorVisitor.php @@ -56,9 +56,9 @@ public function enterNode(Node $node): ?int /** @var LNumber|DNumber|String_ $scalar */ $scalar = $node; - if ($this->hasSign($scalar) && $this->isNumber($scalar)) { + if ($this->hasSign($scalar)) { $node = $scalar->getAttribute('parent'); - if ($this->isMinus($node)) { + if ($this->isMinus($node) && isset($scalar->value)) { $scalar->value = -$scalar->value; } } From 1bb6a9ac0929913d280102dc41eb133133946953 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Thu, 7 Mar 2019 13:21:33 +0000 Subject: [PATCH 11/16] Update DetectorVisitor.php --- src/Visitor/DetectorVisitor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Visitor/DetectorVisitor.php b/src/Visitor/DetectorVisitor.php index c003c8b..a0a02b6 100644 --- a/src/Visitor/DetectorVisitor.php +++ b/src/Visitor/DetectorVisitor.php @@ -64,7 +64,6 @@ public function enterNode(Node $node): ?int } if ($this->isNumber($scalar) || $this->isString($scalar)) { - if ($this->checkNameContainsLanguage( $scalar->getAttribute('parent')->var->name ?? '', $scalar->value From 97d3287032eb26df59c3f249e9a5fc2c3e293561 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Sun, 7 Apr 2019 20:22:43 +0100 Subject: [PATCH 12/16] Add all languages support with intl extension --- composer.json | 3 +- src/Console/Option.php | 23 +++++-- src/Language.php | 28 ++++++++- src/Languages/En.php | 134 ++++++++++++----------------------------- 4 files changed, 85 insertions(+), 103 deletions(-) diff --git a/composer.json b/composer.json index 2dcac70..b668dc8 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "symfony/finder": "^4.0", "nikic/php-parser": "^4.0", "jakub-onderka/php-console-highlighter": "^0.4", - "phpunit/php-timer": "^2.0" + "phpunit/php-timer": "^2.0", + "ext-intl": "*" }, "require-dev": { "phpunit/phpunit": "^7.0", diff --git a/src/Console/Option.php b/src/Console/Option.php index 7cb513b..a99d39a 100644 --- a/src/Console/Option.php +++ b/src/Console/Option.php @@ -3,6 +3,7 @@ namespace Povils\PHPMND\Console; use Povils\PHPMND\Extension\Extension; +use Povils\PHPMND\GenericLanguage; use Povils\PHPMND\Language; /** @@ -151,13 +152,25 @@ public function setCheckNaming(array $checkNaming) { $languages = []; foreach ($checkNaming as $language) { - $language = ucfirst($language); - $className = '\Povils\PHPMND\Languages\\' . $language; + $languages[] = $this->findLanguage($language); + } + $this->checkNaming = $languages; + } - if (class_exists($className)) { - $languages[] = new $className(); + protected function findLanguage($language): Language + { + foreach (scandir(__DIR__ . '/../Languages/') as $class) { + $class = basename($class, '.php'); + $class = "Povils\PHPMND\Languages\\$class"; + if (( + class_exists($class) && + is_subclass_of($class, Language::class) && + in_array($language, $class::providesLanguages()) + )) { + return new $class($language); } } - $this->checkNaming = $languages; + + return new GenericLanguage($language); } } diff --git a/src/Language.php b/src/Language.php index 203d99f..a75d3f1 100644 --- a/src/Language.php +++ b/src/Language.php @@ -2,10 +2,34 @@ namespace Povils\PHPMND; -interface Language +use NumberFormatter; + +abstract class Language { + /** + * @var NumberFormatter + */ + protected $formatter; + + public function __construct($language) + { + $this->formatter = new NumberFormatter($language, NumberFormatter::SPELLOUT); + } + /* * Returns an array of words which */ - public function parse(int $number): array; + public function parse(int $number): array { + $words = $this->specialNumbers()[$number] ?? []; + $formatted = $this->formatter->format($number); + + $formatted = str_replace(['-', ','], ' ', $formatted); + $formatted = explode(' ', $formatted); + + return array_merge($words, $formatted); + } + + abstract public static function providesLanguages(): array; + + abstract public function specialNumbers(): array; } diff --git a/src/Languages/En.php b/src/Languages/En.php index 4b41b5e..701e0dd 100644 --- a/src/Languages/En.php +++ b/src/Languages/En.php @@ -3,103 +3,47 @@ use Povils\PHPMND\Language; -class En implements Language +class En extends Language { - protected $specialNumbers = [ - 2 => [ - 'half', - ], - 3 => [ - 'third', - ], - 7 => [ - 'week', - ], - 10 => [ - 'tenth', - 'decile', - ], - 24 => [ - 'hours', - ], - 28 => [ - 'February', - ], - 60 => [ - 'second', - 'minute', - ], - 100 => [ - 'percent', - 'centile' - ], - ]; - - protected $numberMapping = [ - 'zero', - 'one', - 'two', - 'three', - 'four', - 'five', - 'six', - 'seven', - 'eight', - 'nine', - 'ten', - 'eleven', - 'twelve', - 'thirteen', - 'fourteen', - 'fifteen', - 'sixteen', - 'seventeen', - 'eighteen', - 'nineteen', - 'twenty', - 30 => 'thirty', - 40 => 'forty', - 50 => 'fifty', - 60 => 'sixty', - 70 => 'seventy', - 80 => 'eighty', - 90 => 'ninety', - 100 => 'hundred', - 1000 => 'thousand', - 1000000 => 'million', - ]; - - public function parse(int $number): array + public static function providesLanguages(): array { + return [ + 'en', + 'en_GB', + 'en_US' + ]; + } - end($this->numberMapping); - $final = $this->specialNumbers[$number] ?? []; - - if ($number < 0) { - $final [] = 'minus'; - $final [] = 'negative'; - - $number = -$number; - } - - do { - $key = key($this->numberMapping); - - if ($number < $key) { - continue; - } - $multiple = 1; - - if ($key * 2 < $number && $key > 0) { - $multiple = floor($number / $key); - - $final = array_merge($final, $this->parse($multiple)); - } - - $final[] = current($this->numberMapping); - $number -= $key * $multiple; - } while (prev($this->numberMapping) !== false && $number > 0); - - return $final; + public function specialNumbers(): array + { + return [ + 2 => [ + 'half', + ], + 3 => [ + 'third', + ], + 7 => [ + 'week', + ], + 10 => [ + 'tenth', + 'decile', + ], + 24 => [ + 'hours', + ], + 28 => [ + 'February', + ], + 60 => [ + 'second', + 'minute', + ], + 100 => [ + 'percent', + 'centile' + ], + ]; } } From 7895b809594acf123bb127927a7c254c2ecd6e28 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Sun, 7 Apr 2019 20:25:21 +0100 Subject: [PATCH 13/16] Add missing bits --- src/Console/Command.php | 2 +- src/GenericLanguage.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/GenericLanguage.php diff --git a/src/Console/Command.php b/src/Console/Command.php index 427c77e..c5966bc 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -142,7 +142,7 @@ protected function configure(): void 'check-naming', null, InputOption::VALUE_REQUIRED, - 'Check the names of variables to ensure they are not numeric', + 'Check the names of variables to ensure they are not numeric, accepts a comma separated list of languages eg en or en_GB', '' ) ; diff --git a/src/GenericLanguage.php b/src/GenericLanguage.php new file mode 100644 index 0000000..518fba1 --- /dev/null +++ b/src/GenericLanguage.php @@ -0,0 +1,17 @@ + Date: Mon, 8 Apr 2019 21:42:19 +0100 Subject: [PATCH 14/16] CS fixes --- src/Console/Command.php | 3 ++- src/Language.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Console/Command.php b/src/Console/Command.php index c5966bc..5dd0d58 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -142,7 +142,8 @@ protected function configure(): void 'check-naming', null, InputOption::VALUE_REQUIRED, - 'Check the names of variables to ensure they are not numeric, accepts a comma separated list of languages eg en or en_GB', + 'Check the names of variables to ensure they are not numeric,' . + ' accepts a comma separated list of languages eg en or en_GB', '' ) ; diff --git a/src/Language.php b/src/Language.php index a75d3f1..ceb7795 100644 --- a/src/Language.php +++ b/src/Language.php @@ -19,7 +19,8 @@ public function __construct($language) /* * Returns an array of words which */ - public function parse(int $number): array { + public function parse(int $number): array + { $words = $this->specialNumbers()[$number] ?? []; $formatted = $this->formatter->format($number); From 061317a21c28ae9ddc7c0259cd1144d9b405e625 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Mon, 8 Apr 2019 22:14:20 +0100 Subject: [PATCH 15/16] attempt appveyor fix --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 56804fd..5112e19 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -35,6 +35,7 @@ install: - IF %PHP%==1 echo extension_dir=ext >> php.ini - IF %PHP%==1 echo extension=php_openssl.dll >> php.ini - IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini + - IF %PHP%==1 echo extension=php_intl.dll >> php.ini - IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat # Install composer and update per matrix - appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar From a869472889d8f0e33bdc9535ea9a4bbc85cd2a9e Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Tue, 9 Apr 2019 12:43:33 +0100 Subject: [PATCH 16/16] Minor fix --- src/Visitor/DetectorVisitor.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Visitor/DetectorVisitor.php b/src/Visitor/DetectorVisitor.php index a0a02b6..c552e19 100644 --- a/src/Visitor/DetectorVisitor.php +++ b/src/Visitor/DetectorVisitor.php @@ -135,13 +135,9 @@ private function isValidNumeric(Node $node): bool false === $this->ignoreString($node); } - /** - * @param string $name - * @param string|int $value - * @return bool - */ private function checkNameContainsLanguage(string $name, $value): bool { + $value = (int) $value; foreach ($this->option->checkNaming() as $language) { $generatedNumbers = $language->parse($value);