Skip to content

Commit

Permalink
Merge fc74950 into 5a8b5b0
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rdex committed Aug 4, 2020
2 parents 5a8b5b0 + fc74950 commit 0130b8e
Show file tree
Hide file tree
Showing 34 changed files with 643 additions and 348 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Expand Up @@ -8,6 +8,8 @@ env:
matrix:
fast_finish: true
include:
- php: 7.4
env: RUN_PHPSTAN=1
- php: 7.3
- php: 7.2
# run tests coverage on PHP 7.1
Expand Down Expand Up @@ -37,6 +39,11 @@ install:
script:
- vendor/bin/phpunit $PHPUNIT_FLAGS
- |
if [ $RUN_PHPSTAN == 1 ]; then
composer require --dev phpstan/phpstan
vendor/bin/phpstan analyse
fi
after_script:
- |
Expand Down
24 changes: 24 additions & 0 deletions phpstan.neon
@@ -0,0 +1,24 @@
parameters:
level: 6
reportUnmatchedIgnoredErrors: false
paths:
- src
- tests
ignoreErrors:
-
message: '#Method .* has no return typehint specified#'
path: tests/
-
message: '#Method .* has parameter .* with no typehint specified#'
path: tests/
-
message: '#Method .* has parameter .* with no value type specified in iterable type array#'
path: tests/
-
message: '#Method .* return type has no value type specified in iterable type array#'
path: tests/
-
message: '#PHPDoc tag @param has invalid value \(.*\): Unexpected token ".*", expected type at offset .*#'
path: tests/
- '#Call to static method .* on trait .*#'
- '#Access to static property .* on trait .*#'
31 changes: 25 additions & 6 deletions src/BaseInflection.php
@@ -1,17 +1,36 @@
<?php
namespace morphos;

use RuntimeException;

abstract class BaseInflection implements Cases
{
public static function isMutable($name)
{
/**
* @abstract
* @param string $name
* @return bool
*/
public static function isMutable($name) {
throw new RuntimeException('Not implemented');
}

public static function getCases($name)
{
/**
* @abstract
* @param string $name
* @return string[]
* @phpstan-return array<string, string>
*/
public static function getCases($name) {
throw new RuntimeException('Not implemented');
}

public static function getCase($name, $case)
{
/**
* @abstract
* @param string $name
* @param string $case
* @return string
*/
public static function getCase($name, $case) {
throw new RuntimeException('Not implemented');
}
}
37 changes: 31 additions & 6 deletions src/BasePluralization.php
@@ -1,17 +1,42 @@
<?php
namespace morphos;

use RuntimeException;

abstract class BasePluralization
{
public static function pluralize($word, $count = 2)
{
/**
* @abstract
* @param string $word
* @param int $count
*
* @return string
*/
public static function pluralize($word, $count = 2) {
throw new RuntimeException('Not implemented');
}

public static function getCase($word, $case, $animateness = false)
{
/**
* @abstract
* @param string $word
* @param string $case
* @param bool $animateness
*
* @return string
*/
public static function getCase($word, $case, $animateness = false) {
throw new RuntimeException('Not implemented');
}

public static function getCases($word, $animateness = false)
{
/**
* @abstract
* @param string $word
* @param bool $animateness
*
* @return string[]
* @phpstan-return array<string, string>
*/
public static function getCases($word, $animateness = false) {
throw new RuntimeException('Not implemented');
}
}
9 changes: 6 additions & 3 deletions src/CasesHelper.php
Expand Up @@ -6,7 +6,7 @@
trait CasesHelper
{
/**
* @param $case
* @param string $case
* @return string
* @throws InvalidArgumentException If passed case is invalid.
*/
Expand Down Expand Up @@ -49,7 +49,8 @@ public static function canonizeCase($case)
}

/**
* @return array
* @return string[]
* @phpstan-return array<\morphos\Cases::*>
*/
public static function getAllCases()
{
Expand All @@ -67,8 +68,10 @@ public static function getAllCases()
/**
* Составляет один массив с падежами из нескольких массивов падежей разных слов
* @param array $words Двумерный массив слов и их падежей
* @phpstan-param array<int, array<string, string>> $words
* @param string $delimiter Разделитель между падежами слов
* @return array Одномерный массив падежей
* @return string[] Одномерный массив падежей
* @phpstan-return array<string, string>
*/
public static function composeCasesFromWords(array $words, $delimiter = ' ') {
$cases = [];
Expand Down
2 changes: 1 addition & 1 deletion src/CurrenciesHelper.php
Expand Up @@ -6,7 +6,7 @@
trait CurrenciesHelper
{
/**
* @param $currency
* @param string $currency
* @return string
* @throws InvalidArgumentException
*/
Expand Down
25 changes: 18 additions & 7 deletions src/English/CardinalNumeralGenerator.php
Expand Up @@ -2,9 +2,14 @@
namespace morphos\English;

use morphos\NumeralGenerator;
use RuntimeException;

class CardinalNumeralGenerator extends NumeralGenerator
{
/**
* @var string[]
* @phpstan-var array<int, string>
*/
public static $words = [
1 => 'one',
2 => 'two',
Expand Down Expand Up @@ -35,24 +40,30 @@ class CardinalNumeralGenerator extends NumeralGenerator
90 => 'ninety',
];

/**
* @var string[]
* @phpstan-var array<int, string>
*/
public static $exponents = [
'100' => 'hundred',
'1000' => 'thousand',
'1000000' => 'million',
'1000000000' => 'billion',
'1000000000000' => 'trillion',
100 => 'hundred',
1000 => 'thousand',
1000000 => 'million',
1000000000 => 'billion',
1000000000000 => 'trillion',
];

public static function getCases($number)
{
throw new RuntimeException('Not implemented');
}

public static function getCase($number, $case)
{
throw new RuntimeException('Not implemented');
}

/**
* @param $number
* @param int $number
* @return mixed|string
*/
public static function generate($number)
Expand All @@ -68,7 +79,7 @@ public static function generate($number)

foreach (array_reverse(static::$exponents, true) as $word_number => $word) {
if ($number >= $word_number) {
$count = floor($number / $word_number);
$count = (int)floor($number / $word_number);
$number = $number % ($count * $word_number);
$parts[] = static::generate($count).' '.static::generate($word_number).($word_number != 100 && $number > 0 ? ',' : null);
}
Expand Down
19 changes: 18 additions & 1 deletion src/English/NounPluralization.php
Expand Up @@ -2,9 +2,14 @@
namespace morphos\English;

use morphos\S;
use RuntimeException;

class NounPluralization extends \morphos\BasePluralization
{
/**
* @var string[]
* @phpstan-var array<string, string>
*/
private static $exceptions = [
'chief' => 'chiefs',
'basis' => 'bases',
Expand All @@ -22,6 +27,7 @@ class NounPluralization extends \morphos\BasePluralization
'mouse' => 'mice'
];

/** @var string[] */
private static $without_paired_form = [
'knowledge',
'progress',
Expand All @@ -33,10 +39,11 @@ class NounPluralization extends \morphos\BasePluralization
'trousers',
];

/** @var string[] */
public static $consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'x', 'z', 'w'];

/**
* @param $word
* @param string $word
* @param int $count
* @return string
*/
Expand Down Expand Up @@ -69,4 +76,14 @@ public static function pluralize($word, $count = 2)
return $word.'s';
}
}

public static function getCase($word, $case, $animateness = false)
{
throw new RuntimeException('Not implemented');
}

public static function getCases($word, $animateness = false)
{
throw new RuntimeException('Not implemented');
}
}
11 changes: 9 additions & 2 deletions src/English/OrdinalNumeralGenerator.php
Expand Up @@ -2,9 +2,14 @@
namespace morphos\English;

use morphos\NumeralGenerator;
use RuntimeException;

class OrdinalNumeralGenerator extends NumeralGenerator
{
/**
* @var string[]
* @phpstan-var array<int, string>
*/
protected static $words = [
1 => 'first',
2 => 'second',
Expand All @@ -17,13 +22,15 @@ class OrdinalNumeralGenerator extends NumeralGenerator

public static function getCases($number)
{
throw new RuntimeException('Not implemented');
}
public static function getCase($number, $case)
{
throw new RuntimeException('Not implemented');
}

/**
* @param $number
* @param int $number
* @param bool $short
* @return string
*/
Expand Down Expand Up @@ -52,7 +59,7 @@ public static function generate($number, $short = false)

foreach (array_reverse(CardinalNumeralGenerator::$exponents, true) as $word_number => $word) {
if ($number >= $word_number) {
$count = floor($number / $word_number);
$count = (int)floor($number / $word_number);
$number = $number % ($count * $word_number);
$parts[] = CardinalNumeralGenerator::generate($count).' '.CardinalNumeralGenerator::generate($word_number).($word_number != 100 && $number > 0 ? ',' : null);
}
Expand Down
8 changes: 6 additions & 2 deletions src/English/TimeSpeller.php
Expand Up @@ -5,6 +5,10 @@

class TimeSpeller extends \morphos\TimeSpeller
{
/**
* @var string[]
* @phpstan-var array<string, string>
*/
protected static $units = [
self::YEAR => 'year',
self::MONTH => 'month',
Expand All @@ -15,8 +19,8 @@ class TimeSpeller extends \morphos\TimeSpeller
];

/**
* @param $count
* @param $unit
* @param int $count
* @param string $unit
* @return string
*/
public static function spellUnit($count, $unit)
Expand Down
11 changes: 8 additions & 3 deletions src/MoneySpeller.php
@@ -1,6 +1,8 @@
<?php
namespace morphos;

use RuntimeException;

abstract class MoneySpeller implements Currency
{
const SHORT_FORMAT = 'short';
Expand All @@ -11,15 +13,18 @@ abstract class MoneySpeller implements Currency
/**
* @abstract
*
* @param float $value
* @param float|int $value
* @param string $currency
* @param string $format
* @param null $case
* @param string|null $case
* @return string
*/
public static function spell(
$value,
$currency,
$format = self::NORMAL_FORMAT,
$case = null
) {}
) {
throw new RuntimeException('Not implemented');
}
}

0 comments on commit 0130b8e

Please sign in to comment.