diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 6eeb828..9f7d41c 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -12,4 +12,4 @@ tools: timeout: 600 php_code_sniffer: config: - standard: "PSR2" + standard: "PSR12" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index acb81ea..f646d9c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -44,6 +44,8 @@ Write code and tests. When you are ready, run the tests. $ composer test ``` + + When you are ready with the code, tested it and documented it, you can commit and push it with the following commands: ``` bash @@ -76,9 +78,14 @@ $ git push -f origin feature-or-bug-fix-description ## Coding standard -This repository follows the [PSR-2 standard](http://www.php-fig.org/psr/psr-2/) and so, if you want to contribute, +This repository follows the [PSR-12 standard](https://www.php-fig.org/psr/psr-12/) and so, if you want to contribute, you must follow these rules. +To ensure that your code meets the coding standards, you can run the linter using the following command: + +```bash +$ composer lint +``` ## Semver diff --git a/composer.json b/composer.json index f95bb2d..63c2364 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "type": "library", "license": "MIT", "require-dev": { - "phpunit/phpunit": "^4.0" + "phpunit/phpunit": "^4.0", + "squizlabs/php_codesniffer": "4.x-dev" }, "autoload": { "psr-4": { @@ -25,6 +26,8 @@ ] }, "scripts": { + "lint": "phpcs src", + "lint-fix": "phpcbf src", "test": "vendor/bin/phpunit", "test-ci": "vendor/bin/phpunit -c phpunit.xml.ci" }, diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..811bbc7 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,12 @@ + + + PHPFunct ruleset + + + + + + + + + diff --git a/src/General.php b/src/General.php index 4b8fa1d..acc5f24 100644 --- a/src/General.php +++ b/src/General.php @@ -157,7 +157,7 @@ function true($value) /** * Returns the first param if isset or the second one or null if it doesn't - * + * * @param mixed $value * @param mixed $default * @return mixed diff --git a/src/Strings.php b/src/Strings.php index 99ff69e..0b003f2 100644 --- a/src/Strings.php +++ b/src/Strings.php @@ -107,7 +107,6 @@ function chompLeft($input, $prefix) function chompRight($input, $suffix) { if (endsWith($input, $suffix)) { - return mb_substr($input, 0, mb_strlen($input) - mb_strlen($suffix)); } @@ -654,7 +653,7 @@ function stripPunctuation($string) */ function swapCase($string, $mb = false) { - return array_reduce(str_split($string), function($carry, $item) use ($mb) { + return array_reduce(str_split($string), function ($carry, $item) use ($mb) { return $carry .= isLower($item, $mb) ? toUpper($item, $mb) : toLower($item, $mb); }, ''); } diff --git a/src/Tests/Collection/CollectionFirstNTest.php b/src/Tests/Collection/CollectionFirstNTest.php index 50fa8ed..39d9879 100644 --- a/src/Tests/Collection/CollectionFirstNTest.php +++ b/src/Tests/Collection/CollectionFirstNTest.php @@ -12,10 +12,9 @@ */ class CollectionFirstNTest extends \PHPUnit_Framework_TestCase { - public function testFirst() { - $array = range(1,9); + $array = range(1, 9); $result = Collection\firstN($array, 3); $this->assertEquals([1, 2, 3], $result); diff --git a/src/Tests/Collection/CollectionFirstTest.php b/src/Tests/Collection/CollectionFirstTest.php index f85686d..c8e47e3 100644 --- a/src/Tests/Collection/CollectionFirstTest.php +++ b/src/Tests/Collection/CollectionFirstTest.php @@ -12,10 +12,9 @@ */ class CollectionFirstTest extends \PHPUnit_Framework_TestCase { - public function testFirst() { - $array = range(1,9); + $array = range(1, 9); $result = Collection\first($array); $this->assertEquals(1, $result); diff --git a/src/Tests/Collection/CollectionLastNTest.php b/src/Tests/Collection/CollectionLastNTest.php index 7a78762..0ce5e86 100644 --- a/src/Tests/Collection/CollectionLastNTest.php +++ b/src/Tests/Collection/CollectionLastNTest.php @@ -12,10 +12,9 @@ */ class CollectionLastNTest extends \PHPUnit_Framework_TestCase { - public function testLast() { - $array = range(1,9); + $array = range(1, 9); $result = Collection\lastN($array, 3); $this->assertEquals([7, 8, 9], $result); diff --git a/src/Tests/Collection/CollectionLastTest.php b/src/Tests/Collection/CollectionLastTest.php index 7f44727..c5ca580 100644 --- a/src/Tests/Collection/CollectionLastTest.php +++ b/src/Tests/Collection/CollectionLastTest.php @@ -12,10 +12,9 @@ */ class CollectionLastTest extends \PHPUnit_Framework_TestCase { - public function testLast() { - $array = range(1,9); + $array = range(1, 9); $result = Collection\last($array); $this->assertEquals(9, $result); diff --git a/src/Tests/IfSetOrTest.php b/src/Tests/IfSetOrTest.php index 51f257a..c23662b 100644 --- a/src/Tests/IfSetOrTest.php +++ b/src/Tests/IfSetOrTest.php @@ -17,7 +17,7 @@ public function testIsNotSet() $this->assertNull(Funct\ifSetOr($foo)); $this->assertEquals('bar', Funct\ifSetOr($foo2, 'bar')); } - + public function testIsSet() { $foo = 'foo'; diff --git a/src/Tests/Invoke/InvokeIfIssetTest.php b/src/Tests/Invoke/InvokeIfIssetTest.php index c7c33e9..e9d1e91 100644 --- a/src/Tests/Invoke/InvokeIfIssetTest.php +++ b/src/Tests/Invoke/InvokeIfIssetTest.php @@ -3,7 +3,7 @@ namespace Funct\Tests\Invoke; use Funct\Invoke; -use Funct\Tests\Fixtures\SampleObject;; +use Funct\Tests\Fixtures\SampleObject; /** * Class InvokeIfIssetTest diff --git a/src/Tests/Invoke/InvokeIfNotEmptyTest.php b/src/Tests/Invoke/InvokeIfNotEmptyTest.php index 05390cb..3669ddd 100644 --- a/src/Tests/Invoke/InvokeIfNotEmptyTest.php +++ b/src/Tests/Invoke/InvokeIfNotEmptyTest.php @@ -3,7 +3,7 @@ namespace Funct\Tests\Invoke; use Funct\Invoke; -use Funct\Tests\Fixtures\SampleObject;; +use Funct\Tests\Fixtures\SampleObject; /** * Class InvokeIfNotEmptyTest diff --git a/src/Tests/Objects/AssignIfIssetTest.php b/src/Tests/Objects/AssignIfIssetTest.php index e5b64b9..9d84470 100644 --- a/src/Tests/Objects/AssignIfIssetTest.php +++ b/src/Tests/Objects/AssignIfIssetTest.php @@ -12,7 +12,6 @@ */ class AssignIfIssetTest extends \PHPUnit_Framework_TestCase { - public function testMethod() { $object = new \stdClass(); diff --git a/src/Tests/Strings/StringsChompLeftTest.php b/src/Tests/Strings/StringsChompLeftTest.php index ebd5a0b..7341f53 100644 --- a/src/Tests/Strings/StringsChompLeftTest.php +++ b/src/Tests/Strings/StringsChompLeftTest.php @@ -2,7 +2,7 @@ namespace Funct\Tests\Strings; -use Funct\Strings;; +use Funct\Strings; /** * Class StringsChompLeftTest diff --git a/src/Tests/Strings/StringsIncludesTest.php b/src/Tests/Strings/StringsIncludesTest.php index 98a2037..d1bc712 100644 --- a/src/Tests/Strings/StringsIncludesTest.php +++ b/src/Tests/Strings/StringsIncludesTest.php @@ -21,7 +21,7 @@ public function dataStringIncludes() $out[] = ['foo bar', 'foo', true]; $out[] = ['foo&%$bar@;/', 'bar', true]; $out[] = ['foo BAR', 'bar', false]; - + return $out; } diff --git a/src/Tests/Strings/StringsLatinizeTest.php b/src/Tests/Strings/StringsLatinizeTest.php index 076da57..1b76680 100644 --- a/src/Tests/Strings/StringsLatinizeTest.php +++ b/src/Tests/Strings/StringsLatinizeTest.php @@ -16,12 +16,18 @@ public function dataStringLatinize() { $out = []; - $out[] = ['Dès Noël où un zéphyr haï me vêt de glaçons würmiens je dîne d’exquis rôtis de bœuf au kir à l’aÿ d’âge mûr & cætera !', - 'Des Noel ou un zephyr hai me vet de glacons wurmiens je dine d’exquis rotis de boeuf au kir a l’ay d’age mur & caetera !']; - $out[] = ['Benjamín pidió una bebida de kiwi y fresa; Noé, sin vergüenza, la más exquisita champaña del menú.', - 'Benjamin pidio una bebida de kiwi y fresa; Noe, sin verguenza, la mas exquisita champana del menu.']; - $out[] = ['Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.', - 'Falsches Uben von Xylophonmusik qualt jeden grosseren Zwerg.']; + $out[] = [ + 'Dès Noël où un zéphyr haï me vêt de glaçons würmiens je dîne d’exquis rôtis de bœuf au kir à l’aÿ d’âge mûr & cætera !', + 'Des Noel ou un zephyr hai me vet de glacons wurmiens je dine d’exquis rotis de boeuf au kir a l’ay d’age mur & caetera !' + ]; + $out[] = [ + 'Benjamín pidió una bebida de kiwi y fresa; Noé, sin vergüenza, la más exquisita champaña del menú.', + 'Benjamin pidio una bebida de kiwi y fresa; Noe, sin verguenza, la mas exquisita champana del menu.' + ]; + $out[] = [ + 'Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.', + 'Falsches Uben von Xylophonmusik qualt jeden grosseren Zwerg.' + ]; return $out; } diff --git a/src/Tests/Strings/StringsToLowerTest.php b/src/Tests/Strings/StringsToLowerTest.php index 8000192..6b39941 100644 --- a/src/Tests/Strings/StringsToLowerTest.php +++ b/src/Tests/Strings/StringsToLowerTest.php @@ -38,4 +38,4 @@ public function testStringToLower($input, $mb, $expected) { $this->assertEquals($expected, Strings\toLower($input, $mb)); } -} \ No newline at end of file +}