Skip to content

Commit

Permalink
phpstan used
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Nov 14, 2024
1 parent 9459358 commit 6f9c275
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 101 deletions.
4 changes: 4 additions & 0 deletions src/Ease/Anonym.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Anonym extends Brick implements Person

/**
* User Settings array.
*
* @phpstan-ignore missingType.iterableValue
*/
public array $settings = [];

Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 3 additions & 1 deletion src/Ease/Brick.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class Brick extends Sand
{
use RecordKey;
use recordkey;

/**
* @var string Name Column
Expand Down Expand Up @@ -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
{
Expand Down
61 changes: 18 additions & 43 deletions src/Ease/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> $addParams value to add
* @param bool $override replace already existing values ?
*
* @return string url with parameters added
*/
Expand Down Expand Up @@ -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<mixed> $sourceArray source
* @param array<mixed> $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;

Expand All @@ -110,19 +110,17 @@ public static function divDataArray(&$sourceArray, &$destinationArray, $columNam
/**
* Test for associative array.
*
* @return bool
* @param array<mixed> $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',
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<mixed> $data array to reindex
* @param string $indexBy one of columns in array
*
* @return array
* @return array<mixed> reindexed array
*/
public static function reindexArrayBy(array $data, ?string $indexBy = null)
public static function reindexArrayBy(array $data, string $indexBy)
{
$reindexedData = [];

Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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<string, string> 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());
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Ease/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Locale

/**
* All Language Codes => languages.
*
* @var array<string, string>
*/
public static array $alllngs = [
'af_NA' => 'Afrikaans (Namibia)',
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/Ease/Logger/Regent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ class Regent extends \Ease\Atom implements Loggingable
{
/**
* Here to reach logger objects.
*
* @var array<Loggingable>
*/
public array $loggers = [];

/**
* Hodnoty pro obarvování logu.
*
* @var array<string>
*/
public array $logStyles = [
'notice' => 'color: black;',
Expand Down
2 changes: 1 addition & 1 deletion src/Ease/Logger/ToConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Ease/Logger/ToMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/Ease/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 20 additions & 20 deletions src/Ease/Molecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> $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})) {
Expand All @@ -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;
}
Expand All @@ -115,39 +115,39 @@ 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<string, string> $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);
}
}
}

/**
* 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<string, string> $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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ease/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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ý.
Expand Down
8 changes: 7 additions & 1 deletion src/Ease/Sand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class Sand extends Molecule

/**
* Common object data holder.
*
* @var array<string, mixed>
*/
public ?array $data = null;

Expand Down Expand Up @@ -90,6 +92,8 @@ public function setData(array $data, $reset = false)

/**
* Obtain data holded by object.
*
* @phpstan-ignore missingType.iterableValue
*/
public function getData(): ?array
{
Expand Down Expand Up @@ -153,10 +157,12 @@ public function unsetDataValue(string $columnName): bool

/**
* Převezme data do aktuálního pole dat.
*
* @var array<string, mixed>
*/
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;
Expand Down
Loading

0 comments on commit 6f9c275

Please sign in to comment.