Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- vendor/phpstan/phpstan-deprecation-rules/rules.neon

parameters:
level: 5
phpVersion: 70300
reportUnmatchedIgnoredErrors: false
paths:
- src
2 changes: 1 addition & 1 deletion src/Stemmer/Danish.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/Stemmer/Dutch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/Stemmer/Finnish.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ private function step1()

return true;
}

return false;
}

/**
Expand Down Expand Up @@ -180,6 +182,8 @@ private function step2()
}
}
}

return false;
}

/**
Expand Down Expand Up @@ -294,6 +298,8 @@ private function step3()
$this->_removedInStep3 = true;
return true;
}

return false;
}

/**
Expand Down Expand Up @@ -326,6 +332,8 @@ private function step4()
$this->r2();
return true;
}

return false;
}

/**
Expand Down Expand Up @@ -372,6 +380,7 @@ private function step5()
}
}

return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Stemmer/Norwegian.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/Stemmer/Romanian.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ private function step3()
}
return true;
}

return false;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Stemmer/Spanish.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -301,6 +301,8 @@ private function step2b()

return true;
}

return false;
}

/**
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stemmer/Stem.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class Stem implements Stemmer

/**
* R1 value
* @var integer
* @var string
*/
protected $r1;

Expand Down
2 changes: 1 addition & 1 deletion src/Stemmer/Swedish.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 3 additions & 17 deletions test/CatalanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
5 changes: 5 additions & 0 deletions test/CsvFileIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __destruct()
fclose($this->file);
}

#[\ReturnTypeWillChange]
public function rewind()
{
rewind($this->file);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/CsvFileVerboseIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class CsvFileVerboseIterator extends CsvFileIterator
{
public function rewind()
public function rewind(): void
{
parent::rewind();
$this->_updateKey($this->current());
Expand All @@ -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];
}
}
}
20 changes: 3 additions & 17 deletions test/DanishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
20 changes: 3 additions & 17 deletions test/DutchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
20 changes: 3 additions & 17 deletions test/EnglishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
20 changes: 3 additions & 17 deletions test/FinnishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
20 changes: 3 additions & 17 deletions test/FrenchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Loading
Loading