diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2994d98..d453b90 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,8 +35,8 @@ jobs: max_attempts: 5 command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - - name: Copy PHP Unit Settings - run: cp phpunit.xml.dist phpunit.xml + - name: Execute phpstan + run: vendor/bin/phpstan - name: Execute tests run: vendor/bin/phpunit --verbose diff --git a/composer.json b/composer.json index d58a45c..fb0a0f9 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,9 @@ "joomla/string": ">=2.0.1" }, "require-dev":{ - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.0", + "phpstan/phpstan": "^2", + "phpstan/phpstan-deprecation-rules": "^2" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..4351197 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,9 @@ +includes: + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + +parameters: + level: 5 + phpVersion: 70300 + reportUnmatchedIgnoredErrors: false + paths: + - src diff --git a/src/Stemmer/Danish.php b/src/Stemmer/Danish.php index 5fc7507..aedd4c2 100644 --- a/src/Stemmer/Danish.php +++ b/src/Stemmer/Danish.php @@ -46,7 +46,7 @@ public function stem($word): string * Define a valid s-ending as one of * a b c d f g h j k l m n o p r t v y z å * - * @param string $ending + * @param string $word * @return boolean */ private function hasValidSEnding($word) diff --git a/src/Stemmer/Dutch.php b/src/Stemmer/Dutch.php index 6a2b563..002c2d7 100644 --- a/src/Stemmer/Dutch.php +++ b/src/Stemmer/Dutch.php @@ -61,7 +61,7 @@ public function stem($word) /** * Define a valid s-ending as a non-vowel other than j. - * @param string $ending + * @param string $word * @return boolean */ private function hasValidSEnding($word) @@ -72,7 +72,7 @@ private function hasValidSEnding($word) /** * Define a valid en-ending as a non-vowel, and not gem. - * @param string $ending + * @param string $word * @return boolean */ private function hasValidEnEnding($word) diff --git a/src/Stemmer/Finnish.php b/src/Stemmer/Finnish.php index c6487b5..d73e4de 100644 --- a/src/Stemmer/Finnish.php +++ b/src/Stemmer/Finnish.php @@ -91,6 +91,8 @@ private function step1() return true; } + + return false; } /** @@ -180,6 +182,8 @@ private function step2() } } } + + return false; } /** @@ -294,6 +298,8 @@ private function step3() $this->_removedInStep3 = true; return true; } + + return false; } /** @@ -326,6 +332,8 @@ private function step4() $this->r2(); return true; } + + return false; } /** @@ -372,6 +380,7 @@ private function step5() } } + return false; } /** diff --git a/src/Stemmer/Norwegian.php b/src/Stemmer/Norwegian.php index 627a578..83969f0 100644 --- a/src/Stemmer/Norwegian.php +++ b/src/Stemmer/Norwegian.php @@ -46,7 +46,7 @@ public function stem($word) * b c d f g h j l m n o p r t v y z, * or k not preceded by a vowel * - * @param string $ending + * @param string $word * @return boolean */ private function hasValidSEnding($word) diff --git a/src/Stemmer/Romanian.php b/src/Stemmer/Romanian.php index 87047dc..fbdd168 100644 --- a/src/Stemmer/Romanian.php +++ b/src/Stemmer/Romanian.php @@ -300,6 +300,8 @@ private function step3() } return true; } + + return false; } /** diff --git a/src/Stemmer/Spanish.php b/src/Stemmer/Spanish.php index b83c040..dea6742 100644 --- a/src/Stemmer/Spanish.php +++ b/src/Stemmer/Spanish.php @@ -98,7 +98,7 @@ private function step0() // c if ( ($position2 = $this->searchIfInRv(array('yendo' . $suffixe))) != false) { $before = StringHelper::substr($this->word, ($position2-1), 1); - if ( (isset($before)) && ($before == 'u') ) { + if ($before == 'u') { $this->word = StringHelper::substr($this->word, 0, $position); return true; } @@ -259,7 +259,7 @@ private function step2a() 'yamos', 'yendo', 'yeron', 'yan', 'yen', 'yais', 'yas', 'yes', 'yo', 'yó', 'ya', 'ye'))) != false) { $before = StringHelper::substr($this->word, ($position-1), 1); - if ( (isset($before)) && ($before == 'u') ) { + if ($before == 'u') { $this->word = StringHelper::substr($this->word, 0, $position); return true; } @@ -301,6 +301,8 @@ private function step2b() return true; } + + return false; } /** @@ -323,7 +325,7 @@ private function step3() if ( ($position2 = $this->searchIfInRv(array('u'))) != false) { $before = StringHelper::substr($this->word, ($position2-1), 1); - if ( (isset($before)) && ($before == 'g') ) { + if ($before == 'g') { $this->word = StringHelper::substr($this->word, 0, $position2); return true; } diff --git a/src/Stemmer/Stem.php b/src/Stemmer/Stem.php index 1ce7274..28d22f2 100644 --- a/src/Stemmer/Stem.php +++ b/src/Stemmer/Stem.php @@ -40,7 +40,7 @@ abstract class Stem implements Stemmer /** * R1 value - * @var integer + * @var string */ protected $r1; diff --git a/src/Stemmer/Swedish.php b/src/Stemmer/Swedish.php index ed8103c..40bb794 100644 --- a/src/Stemmer/Swedish.php +++ b/src/Stemmer/Swedish.php @@ -45,7 +45,7 @@ public function stem($word) * Define a valid s-ending as one of * b c d f g h j k l m n o p r t v y * - * @param string $ending + * @param string $word * @return boolean */ private function hasValidSEnding($word) diff --git a/test/CatalanTest.php b/test/CatalanTest.php index 2512c48..2388fdf 100644 --- a/test/CatalanTest.php +++ b/test/CatalanTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Catalan; -class CatalanTest extends TestCase +class CatalanTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Catalan(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileVerboseIterator('test/files/ca.txt'); - } + protected $class = Catalan::class; + protected $file = 'ca'; } diff --git a/test/CsvFileIterator.php b/test/CsvFileIterator.php index ddc0b23..bf1ed17 100644 --- a/test/CsvFileIterator.php +++ b/test/CsvFileIterator.php @@ -19,6 +19,7 @@ public function __destruct() fclose($this->file); } + #[\ReturnTypeWillChange] public function rewind() { rewind($this->file); @@ -32,21 +33,25 @@ public function rewind() $this->key = 0; } + #[\ReturnTypeWillChange] public function valid() { return !feof($this->file); } + #[\ReturnTypeWillChange] public function key() { return $this->key; } + #[\ReturnTypeWillChange] public function current() { return $this->current; } + #[\ReturnTypeWillChange] public function next() { $line = fgets($this->file); diff --git a/test/CsvFileVerboseIterator.php b/test/CsvFileVerboseIterator.php index 25314b6..f745ab2 100644 --- a/test/CsvFileVerboseIterator.php +++ b/test/CsvFileVerboseIterator.php @@ -3,7 +3,7 @@ class CsvFileVerboseIterator extends CsvFileIterator { - public function rewind() + public function rewind(): void { parent::rewind(); $this->_updateKey($this->current()); @@ -20,9 +20,9 @@ public function next() protected function _updateKey($value) { if ($value && sizeof($value)) { - $this->key = $value[0]; + $this->key = (int) $value[0]; } elseif (sizeof($this->current)) { - $this->key = $this->current[0]; + $this->key = (int) $this->current[0]; } } } diff --git a/test/DanishTest.php b/test/DanishTest.php index b846d72..c01c5fd 100644 --- a/test/DanishTest.php +++ b/test/DanishTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Danish; -class DanishTest extends TestCase +class DanishTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Danish(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/dk.txt'); - } + protected $class = Danish::class; + protected $file = 'dk'; } diff --git a/test/DutchTest.php b/test/DutchTest.php index 6e21f8c..8083bf4 100644 --- a/test/DutchTest.php +++ b/test/DutchTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Dutch; -class DutchTest extends TestCase +class DutchTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Dutch(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/nl.txt'); - } + protected $class = Dutch::class; + protected $file = 'nl'; } diff --git a/test/EnglishTest.php b/test/EnglishTest.php index a38fb0f..cdb05f9 100644 --- a/test/EnglishTest.php +++ b/test/EnglishTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\English; -class EnglishTest extends TestCase +class EnglishTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new English(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/en.txt'); - } + protected $class = English::class; + protected $file = 'en'; } diff --git a/test/FinnishTest.php b/test/FinnishTest.php index 17a6c33..e2ad387 100644 --- a/test/FinnishTest.php +++ b/test/FinnishTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Finnish; -class FinnishTest extends TestCase +class FinnishTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Finnish(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/fi.txt'); - } + protected $class = Finnish::class; + protected $file = 'fi'; } diff --git a/test/FrenchTest.php b/test/FrenchTest.php index a985d2a..159fbfa 100644 --- a/test/FrenchTest.php +++ b/test/FrenchTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\French; -class FrenchTest extends TestCase +class FrenchTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new French(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/fr.txt'); - } + protected $class = French::class; + protected $file = 'fr'; } diff --git a/test/GermanTest.php b/test/GermanTest.php index 3bec53d..f852ff1 100644 --- a/test/GermanTest.php +++ b/test/GermanTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\German; -class GermanTest extends TestCase +class GermanTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new German(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/de.txt'); - } + protected $class = German::class; + protected $file = 'de'; } diff --git a/test/ItalianTest.php b/test/ItalianTest.php index c77d8ac..e4e3f89 100644 --- a/test/ItalianTest.php +++ b/test/ItalianTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Italian; -class ItalianTest extends TestCase +class ItalianTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Italian(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/it.txt'); - } + protected $class = Italian::class; + protected $file = 'it'; } diff --git a/test/NorwegianTest.php b/test/NorwegianTest.php index 6265d58..d30f19c 100644 --- a/test/NorwegianTest.php +++ b/test/NorwegianTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Norwegian; -class NorwegianTest extends TestCase +class NorwegianTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Norwegian(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/no.txt'); - } + protected $class = Norwegian::class; + protected $file = 'no'; } diff --git a/test/PortugueseTest.php b/test/PortugueseTest.php index 6cf8851..267f401 100644 --- a/test/PortugueseTest.php +++ b/test/PortugueseTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Portuguese; -class PortugueseTest extends TestCase +class PortugueseTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Portuguese(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/pt.txt'); - } + protected $class = Portuguese::class; + protected $file = 'pt'; } diff --git a/test/RomanianTest.php b/test/RomanianTest.php index 150510b..ed83a55 100644 --- a/test/RomanianTest.php +++ b/test/RomanianTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Romanian; -class RomanianTest extends TestCase +class RomanianTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Romanian(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/ro.txt'); - } + protected $class = Romanian::class; + protected $file = 'ro'; } diff --git a/test/RussianTest.php b/test/RussianTest.php index e95a6c9..5583f3e 100644 --- a/test/RussianTest.php +++ b/test/RussianTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Russian; -class RussianTest extends TestCase +class RussianTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Russian(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/ru.txt'); - } + protected $class = Russian::class; + protected $file = 'ru'; } diff --git a/test/SpanishTest.php b/test/SpanishTest.php index 7b3cf40..d6f66dd 100644 --- a/test/SpanishTest.php +++ b/test/SpanishTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Spanish; -class SpanishTest extends TestCase +class SpanishTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Spanish(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/es.txt'); - } + protected $class = Spanish::class; + protected $file = 'es'; } diff --git a/test/StemmingTest.php b/test/StemmingTest.php new file mode 100644 index 0000000..8e97085 --- /dev/null +++ b/test/StemmingTest.php @@ -0,0 +1,24 @@ +class; + + $snowballStem = $o->stem($word); + + $this->assertEquals($stem, $snowballStem); + } + + public function load() + { + return new CsvFileIterator('test/files/' . $this->file . '.txt'); + } +} diff --git a/test/SwedishTest.php b/test/SwedishTest.php index f3d1f71..8a9dc3c 100644 --- a/test/SwedishTest.php +++ b/test/SwedishTest.php @@ -4,22 +4,8 @@ use PHPUnit\Framework\TestCase; use Wamania\Snowball\Stemmer\Swedish; -class SwedishTest extends TestCase +class SwedishTest extends StemmingTest { - /** - * @dataProvider load - */ - public function testStem($word, $stem) - { - $o = new Swedish(); - - $snowballStem = $o->stem($word); - - $this->assertEquals($stem, $snowballStem); - } - - public function load() - { - return new CsvFileIterator('test/files/sw.txt'); - } + protected $class = Swedish::class; + protected $file = 'sw'; }