diff --git a/src/Ease/Anonym.php b/src/Ease/Anonym.php index b52251f..86b2b6b 100644 --- a/src/Ease/Anonym.php +++ b/src/Ease/Anonym.php @@ -44,6 +44,8 @@ class Anonym extends Brick implements Person /** * User Settings array. + * + * @phpstan-ignore missingType.iterableValue */ public array $settings = []; @@ -162,6 +164,8 @@ public function getPermission(string $permKeyword): ?string /** * Anonym cannot be signed in. + * + * @phpstan-ignore missingType.iterableValue */ public function tryToLogin(array $formData): bool { diff --git a/src/Ease/Brick.php b/src/Ease/Brick.php index 3f940bf..da3447f 100644 --- a/src/Ease/Brick.php +++ b/src/Ease/Brick.php @@ -24,7 +24,7 @@ class Brick extends Sand { - use RecordKey; + use recordkey; /** * @var string Name Column @@ -169,6 +169,8 @@ public function setInit($init): void /** * Set/override object properties objectName and keyColumn. + * + * @phpstan-ignore missingType.iterableValue */ public function setProperties(array $properties = []): void { diff --git a/src/Ease/Functions.php b/src/Ease/Functions.php index 03c20ca..b68c750 100644 --- a/src/Ease/Functions.php +++ b/src/Ease/Functions.php @@ -48,9 +48,9 @@ public static function sysFilename($path) /** * Add params to url. * - * @param string $url originall url - * @param array $addParams value to add - * @param bool $override replace already existing values ? + * @param string $url originall url + * @param array $addParams value to add + * @param bool $override replace already existing values ? * * @return string url with parameters added */ @@ -89,11 +89,11 @@ public static function addUrlParams($url, array $addParams, $override = false) /** * Move data field $columName from $sourceArray to $destinationArray. * - * @param array $sourceArray source - * @param array $destinationArray destination - * @param string $columName item to move + * @param array $sourceArray source + * @param array $destinationArray destination + * @param string $columName item to move */ - public static function divDataArray(&$sourceArray, &$destinationArray, $columName) + public static function divDataArray(array &$sourceArray, array &$destinationArray, $columName): bool { $result = false; @@ -110,19 +110,17 @@ public static function divDataArray(&$sourceArray, &$destinationArray, $columNam /** * Test for associative array. * - * @return bool + * @param array $arr */ - public static function isAssoc(array $arr) + public static function isAssoc(array $arr): bool { return array_keys($arr) !== range(0, \count($arr) - 1); } /** * Odstraní z textu diakritiku. - * - * @param string $text */ - public static function rip($text) + public static function rip(string $text) { $convertTable = [ 'ä' => 'a', @@ -273,12 +271,8 @@ public static function randomNumber($minimal = null, $maximal = null) /** * Vrací náhodný řetězec dané délky. - * - * @param int $length - * - * @return string */ - public static function randomString($length = 6) + public static function randomString(int $length = 6): string { return substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, $length); } @@ -340,12 +334,12 @@ public static function humanFilesize(int $filesize) /** * Reindex Array by given key. * - * @param array $data array to reindex - * @param string $indexBy one of columns in array + * @param array $data array to reindex + * @param string $indexBy one of columns in array * - * @return array + * @return array reindexed array */ - public static function reindexArrayBy(array $data, ?string $indexBy = null) + public static function reindexArrayBy(array $data, string $indexBy) { $reindexedData = []; @@ -455,21 +449,6 @@ public static function formatBytes($dbytes) return $humanReadable; } - /** - * Get configuration from constant or environment. - * - * @deprecated since version 1.40.1 use \Ease\Shared::cfg() instead - * - * @param string $constant - * @param mixed $cfg Default value - * - * @return null|bool|int|string - */ - public static function cfg(/* string */ $constant, $cfg = null) - { - return \Ease\Shared::cfg($constant, $cfg); - } - /** * Get All Classes in namespace. * @@ -498,11 +477,9 @@ public static function classesInNamespace($namespace) * Load all files found for given namespace * (based on composer files). * - * @param string $namespace - * - * @return array of loaded files className=>filePath + * @return array of loaded files className=>filePath */ - public static function loadClassesInNamespace($namespace) + public static function loadClassesInNamespace(string $namespace): array { $loaded = []; $autoloader = preg_grep('/autoload\.php$/', get_included_files()); @@ -540,10 +517,8 @@ public static function loadClassesInNamespace($namespace) * Generates RFC 4122 compliant Version 4 UUIDs. * * @param string $data - * - * @return string */ - public static function guidv4($data = null) + public static function guidv4($data = null): string { // Generate 16 bytes (128 bits) of random data or use the data passed into the function. $data ??= random_bytes(16); diff --git a/src/Ease/Locale.php b/src/Ease/Locale.php index 52e01cc..eb8da95 100644 --- a/src/Ease/Locale.php +++ b/src/Ease/Locale.php @@ -53,6 +53,8 @@ class Locale /** * All Language Codes => languages. + * + * @var array */ public static array $alllngs = [ 'af_NA' => 'Afrikaans (Namibia)', @@ -523,7 +525,7 @@ public function __construct($setLocale = null, $i18n = '../i18n', $textDomain = * * @return string locale code */ - public static function getPreferedLocale($allowCli = true) + public static function getPreferedLocale(bool $allowCli = true) { // $locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); if (\PHP_SAPI === 'cli' && $allowCli) { diff --git a/src/Ease/Logger/Regent.php b/src/Ease/Logger/Regent.php index df316d8..7221e80 100644 --- a/src/Ease/Logger/Regent.php +++ b/src/Ease/Logger/Regent.php @@ -29,11 +29,15 @@ class Regent extends \Ease\Atom implements Loggingable { /** * Here to reach logger objects. + * + * @var array */ public array $loggers = []; /** * Hodnoty pro obarvování logu. + * + * @var array */ public array $logStyles = [ 'notice' => 'color: black;', diff --git a/src/Ease/Logger/ToConsole.php b/src/Ease/Logger/ToConsole.php index da8de6b..9c5b7a3 100644 --- a/src/Ease/Logger/ToConsole.php +++ b/src/Ease/Logger/ToConsole.php @@ -158,7 +158,7 @@ public function addToLog($caller, $message, $type = 'message') * * @param string $type mail|warning|error|debug|success|info */ - public static function getTypeColor($type) + public static function getTypeColor(string $type): string { switch ($type) { case 'mail': // Envelope diff --git a/src/Ease/Logger/ToMemory.php b/src/Ease/Logger/ToMemory.php index a6a864e..e9f0682 100644 --- a/src/Ease/Logger/ToMemory.php +++ b/src/Ease/Logger/ToMemory.php @@ -73,7 +73,7 @@ class ToMemory extends \Ease\Atom implements Loggingable /** * Saves obejct instace (singleton...). */ - private static $instance; + private static self $instance; /** * Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako diff --git a/src/Ease/Mailer.php b/src/Ease/Mailer.php index 5ba8574..011668b 100644 --- a/src/Ease/Mailer.php +++ b/src/Ease/Mailer.php @@ -128,8 +128,6 @@ public function __construct(string $emailAddress, string $mailSubject, $emailCon /** * Sets mail's text body. * - * @param string $text - * * @return bool|\Pear_Err */ public function setMailBody(string $text) diff --git a/src/Ease/Molecule.php b/src/Ease/Molecule.php index e832345..15e149d 100644 --- a/src/Ease/Molecule.php +++ b/src/Ease/Molecule.php @@ -65,18 +65,18 @@ public function getObjectName() /** * Set up one of the properties by 1) array 2) ENV 3) Constant. * - * @param array $options array of given available properties - * @param string $name name of property to set up - * @param string $constant load default property value from constant / ENV + * @param array $options array of given available properties + * @param string $name name of property to set up + * @param string $constant load default property value from constant / ENV */ - public function setupProperty($options, $name, $constant = ''): void + public function setupProperty(array $options, string $name, string $constant = ''): void { if (\array_key_exists($name, $options)) { $this->{$name} = $options[$name]; } elseif (\array_key_exists($constant, $options)) { $this->{$name} = $options[$constant]; } else { // If No values specified we must use constants or environment - $value = Functions::cfg($constant); + $value = Shared::cfg($constant); if ($constant && (empty($value) === false)) { switch (\gettype($this->{$name})) { @@ -92,19 +92,19 @@ public function setupProperty($options, $name, $constant = ''): void break; default: - $this->{$name} = (bool) Functions::cfg($constant); + $this->{$name} = (bool) Shared::cfg($constant); break; } break; case 'string': - $this->{$name} = (string) Functions::cfg($constant); + $this->{$name} = (string) Shared::cfg($constant); break; default: - $this->{$name} = Functions::cfg($constant); + $this->{$name} = Shared::cfg($constant); break; } @@ -115,19 +115,19 @@ public function setupProperty($options, $name, $constant = ''): void /** * Set up one of the properties by 1) array 2) ENV 3) Constant to int value. * - * @param array $options array of given available properties - * @param string $name name of property to set up - * @param string $constant load default property value from constant / ENV + * @param array $options array of given available properties + * @param string $name name of property to set up + * @param string $constant load default property value from constant / ENV */ - public function setupIntProperty($options, $name, $constant = ''): void + public function setupIntProperty(array $options, string $name, string $constant = ''): void { if (\array_key_exists($name, $options)) { $this->{$name} = (int) $options[$name]; } elseif (\array_key_exists($constant, $options)) { $this->{$name} = (int) $options[$constant]; } else { // If No values specified we must use constants or environment - if ($constant && (empty(Functions::cfg($constant)) === false)) { - $this->{$name} = (int) Functions::cfg($constant); + if ($constant && (empty(Shared::cfg($constant)) === false)) { + $this->{$name} = (int) Shared::cfg($constant); } } } @@ -135,19 +135,19 @@ public function setupIntProperty($options, $name, $constant = ''): void /** * Set up one of the properties by 1) array 2) ENV 3) Constant to bool value. * - * @param array $options array of given availble properties - * @param string $name name of property to set up - * @param string $constant load default property value from constant / ENV + * @param array $options array of given availble properties + * @param string $name name of property to set up + * @param string $constant load default property value from constant / ENV */ - public function setupBoolProperty($options, $name, $constant = ''): void + public function setupBoolProperty(array $options, string $name, string $constant = ''): void { if (\array_key_exists($name, $options)) { $this->{$name} = (bool) $options[$name]; } elseif (\array_key_exists($constant, $options)) { $this->{$name} = (bool) $options[$constant]; } else { // If No values specified we must use constants or environment - if ($constant && (empty(Functions::cfg($constant)) === false)) { - $this->{$name} = (bool) Functions::cfg($constant); + if ($constant && (empty(Shared::cfg($constant)) === false)) { + $this->{$name} = (bool) Shared::cfg($constant); } } } diff --git a/src/Ease/Person.php b/src/Ease/Person.php index e2eab73..c8037e0 100644 --- a/src/Ease/Person.php +++ b/src/Ease/Person.php @@ -28,12 +28,12 @@ public function getUserLevel(); /** * Anonym nema ID. */ - public function getUserID(); + public function getUserID(): ?int; /** * Anonym nemá login. */ - public function getUserLogin(); + public function getUserLogin(): ?string; /** * Anonym nemůže být přihlášený. diff --git a/src/Ease/Sand.php b/src/Ease/Sand.php index c5e6195..06502bd 100644 --- a/src/Ease/Sand.php +++ b/src/Ease/Sand.php @@ -39,6 +39,8 @@ class Sand extends Molecule /** * Common object data holder. + * + * @var array */ public ?array $data = null; @@ -90,6 +92,8 @@ public function setData(array $data, $reset = false) /** * Obtain data holded by object. + * + * @phpstan-ignore missingType.iterableValue */ public function getData(): ?array { @@ -153,10 +157,12 @@ public function unsetDataValue(string $columnName): bool /** * Převezme data do aktuálního pole dat. + * + * @var array */ public function takeData(array $data): int { - if (\is_array($this->data) && \is_array($data)) { + if (\is_array($this->data)) { $this->data = array_merge($this->data, $data); } else { $this->data = $data; diff --git a/src/Ease/Shared.php b/src/Ease/Shared.php index 2132a9a..6535e18 100644 --- a/src/Ease/Shared.php +++ b/src/Ease/Shared.php @@ -21,6 +21,8 @@ namespace Ease; +use Composer\InstalledVersions; + /** * Common shared object. * @@ -31,6 +33,8 @@ class Shared extends Atom { /** * Pole konfigurací. + * + * @var array */ public array $configuration = []; @@ -48,6 +52,8 @@ class Shared extends Atom /** * Status messeges lives here. + * + * @var array */ public static array $statusMessages = []; @@ -322,9 +328,9 @@ public static function &user(?Person $user = null, string $candidat = 'User', st * @param string $configFile Path to file with configuration * @param bool $defineConstants false to do not define constants * - * @return array full configuration array + * @return array full configuration array */ - public function loadConfig($configFile, $defineConstants = false) + public function loadConfig(string $configFile, bool $defineConstants = false) { switch (strtolower(pathinfo($configFile, \constant('PATHINFO_EXTENSION')))) { case 'json': diff --git a/src/Ease/User.php b/src/Ease/User.php index 42d2739..f998c12 100644 --- a/src/Ease/User.php +++ b/src/Ease/User.php @@ -85,6 +85,7 @@ class User extends Anonym /** * Store of user permissions. + * @var array */ public array $permissions = []; @@ -195,7 +196,7 @@ public function getIcon(): string /** * Try to Sign in. * - * @param array $formData pole dat z přihlaš. formuláře např. $_REQUEST + * @param array $formData data from form */ public function tryToLogin(array $formData): bool { diff --git a/src/Ease/RecordKey.php b/src/Ease/recordkey.php similarity index 82% rename from src/Ease/RecordKey.php rename to src/Ease/recordkey.php index 1a8a667..85a3d42 100644 --- a/src/Ease/RecordKey.php +++ b/src/Ease/recordkey.php @@ -23,7 +23,7 @@ /** * @author Vítězslav Dvořák */ -trait RecordKey +trait recordkey { /** * Key Column for Current Record. @@ -31,11 +31,9 @@ trait RecordKey public string $keyColumn = 'id'; /** - * Obtain data holded by object. - * - * @return array + * Obtain data holden by object. */ - abstract public function getData(); + abstract public function getData(): ?array; /** * Set data filed value. @@ -45,7 +43,7 @@ abstract public function getData(); * * @return bool Success */ - abstract public function setDataValue(string $columnName, $value); + abstract public function setDataValue(string $columnName, $value): bool; /** * Gives you value of KEY Column. @@ -54,11 +52,11 @@ abstract public function setDataValue(string $columnName, $value); * * @return int key column value */ - public function getMyKey($data = null) + public function getMyKey(?array $data = []) { - return null === $data ? $this->getDataValue($this->getKeyColumn()) : - (\array_key_exists($this->getKeyColumn(), $data) ? - $data[$this->getKeyColumn()] : null); + return empty($data) ? $this->getDataValue($this->getKeyColumn()) : + (\array_key_exists($this->getKeyColumn(), $data) ? + $data[$this->getKeyColumn()] : null); } /** diff --git a/tests/SandTester.php b/tests/SandTester.php index 284ae1f..7aa7e94 100644 --- a/tests/SandTester.php +++ b/tests/SandTester.php @@ -20,7 +20,7 @@ */ class SandTester extends \Ease\Sand { - use \Ease\RecordKey; + use \Ease\recordkey; // /** // * diff --git a/tests/src/Ease/FunctionsTest.php b/tests/src/Ease/FunctionsTest.php index 6a17aee..e981a8c 100644 --- a/tests/src/Ease/FunctionsTest.php +++ b/tests/src/Ease/FunctionsTest.php @@ -53,7 +53,7 @@ public function testAddUrlParams(): void 'http://vitexsoftware.cz/path?a=b&id=1', Functions::addUrlParams( 'http://vitexsoftware.cz/path?a=b', - ['id' => 1], + ['id' => '1'], true, ), ); @@ -61,7 +61,7 @@ public function testAddUrlParams(): void 'http://vitexsoftware.cz:80?id=1', Functions::addUrlParams( 'http://vitexsoftware.cz:80', - ['id' => 1], + ['id' => '1'], true, ), ); @@ -288,18 +288,6 @@ public function testFormatBytes(): void ); } - /** - * @covers \Functions::cfg - */ - public function testCfg(): void - { - $this->assertEquals('x', Functions::cfg('EASE_TEST', 'x'), 'default value not used'); - putenv('EASE_TEST=a'); - $this->assertEquals('a', Functions::cfg('EASE_TEST'), 'unexepected environment value'); - \define('EASE_TEST', 'b'); - $this->assertEquals('b', Functions::cfg('EASE_TEST')); - } - /** * @covers \Functions::classesInNamespace */ diff --git a/tests/src/Ease/RecordKeyTest.php b/tests/src/Ease/recordkeyTest.php similarity index 96% rename from tests/src/Ease/RecordKeyTest.php rename to tests/src/Ease/recordkeyTest.php index 4505a78..5ca5da9 100644 --- a/tests/src/Ease/RecordKeyTest.php +++ b/tests/src/Ease/recordkeyTest.php @@ -18,7 +18,7 @@ * * @author Vítězslav Dvořák */ -class RecordKeyTest extends \PHPUnit\Framework\TestCase +class recordkeyTest extends \PHPUnit\Framework\TestCase { protected $object;