Skip to content

Commit

Permalink
Code updates using PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Nov 25, 2024
1 parent eb8c99a commit b9d9e86
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 49 deletions.
10 changes: 5 additions & 5 deletions src/Ease/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function addUrlParams($url, array $addParams, $override = false)
*
* @param array<mixed> $sourceArray source
* @param array<mixed> $destinationArray destination
* @param string $columName item to move
* @param int|string $columName item to move
*/
public static function divDataArray(array &$sourceArray, array &$destinationArray, $columName): bool
{
Expand Down Expand Up @@ -120,7 +120,7 @@ public static function isAssoc(array $arr): bool
/**
* Odstraní z textu diakritiku.
*/
public static function rip(string $text)
public static function rip(string $text): string
{
$convertTable = [
'ä' => 'a',
Expand Down Expand Up @@ -209,7 +209,7 @@ public static function rip(string $text)
'Ź' => 'Z',
];

return iconv('UTF-8', 'ASCII//TRANSLIT', strtr($text, $convertTable));
return (string) iconv('UTF-8', 'ASCII//TRANSLIT', strtr($text, $convertTable));
}

/**
Expand Down Expand Up @@ -280,9 +280,9 @@ public static function randomString(int $length = 6): string
/**
* Array content recusrsive recode.
*
* @param array|string $arr original array
* @param array<mixed>|string $arr original array
*
* @return array array recoded
* @return array<mixed> array recoded
*/
public static function recursiveIconv(string $inCharset, string $outCharset, $arr)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Ease/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ public static function browserLocale()
/**
* List of availble locales.
*
* @return array locales availble
* @return array<string, string> locales availble
*/
public function availble()
public function availble(): array
{
$locales = [];
$directory = dir(self::$i18n);
Expand Down
8 changes: 4 additions & 4 deletions src/Ease/Logger/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function addStatusMessage($message, $type = 'info', $caller = null)
/**
* Obtain global status messages.
*
* @return array
* @return Message[] messages
*/
public function getStatusMessages()
public function getStatusMessages(): array
{
return $this->getLogger()->getMessages();
}
Expand All @@ -73,11 +73,11 @@ public function cleanSatatusMessages()
/**
* Provide logger object.
*
* @param array|string $options
* @param array<string, string> $options
*
* @return Regent
*/
public function getLogger($options = null)
public function getLogger(?array $options = null)
{
if (null === $this->logger) {
$this->logger = Regent::singleton($options);
Expand Down
10 changes: 6 additions & 4 deletions src/Ease/Logger/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class Message
* @var string info|succes|warning|error|mail|debug|event
*/
public string $type;
public $caller;

/**
* Message producing Object.
*/
public mixed $caller;

/**
* Message Timestamp.
Expand Down Expand Up @@ -170,10 +174,8 @@ public static function getTypeUnicodeSymbol($type, $color = true)
* Obtain object name from caller object.
*
* @param object|string $caller
*
* @return string
*/
public static function getCallerName($caller)
public static function getCallerName($caller): string
{
if (\is_object($caller)) {
if (method_exists($caller, 'getObjectName')) {
Expand Down
8 changes: 2 additions & 6 deletions src/Ease/Logger/ToFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ToFile extends ToMemory implements Loggingable
/**
* Saves obejct instace (singleton...).
*/
private static $instance;
private static self $instance;

/**
* Logovací třída.
Expand All @@ -88,12 +88,8 @@ public function __destruct()

/**
* Get instanece of File Logger.
*
* @param string $logdir
*
* @return ToFile
*/
public static function singleton($logdir = null)
public static function singleton(string $logdir = ''): self
{
if (!isset(self::$instance)) {
self::$instance = new self($logdir);
Expand Down
14 changes: 5 additions & 9 deletions src/Ease/Logger/ToMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ class ToMemory extends \Ease\Atom implements Loggingable

/**
* Messages live here.
*
* @var array<string, array<string, string>>
*/
public static array $statusMessages = [];

/**
* Hodnoty pro obarvování logu.
*
* @var array<string, string>
*/
public array $logStyles = [
'notice' => 'color: black;',
Expand Down Expand Up @@ -75,15 +79,7 @@ class ToMemory extends \Ease\Atom implements Loggingable
*/
private static self $instance;

/**
* Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako
* konstruktor) se bude v ramci behu programu pouzivat pouze jedna jeho
* instance (ta prvni).
*
* @see http://docs.php.net/en/language.oop5.patterns.html Dokumentace a
* priklad
*/
public static function singleton()
public static function singleton(): self
{
if (!isset(self::$instance)) {
$class = __CLASS__;
Expand Down
16 changes: 5 additions & 11 deletions src/Ease/Logger/ToStd.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Log to stdout/stderr.
*
* @author Vitex <[email protected]>
* @copyright 2009-2023 [email protected] (G)
* @copyright 2009-2024 [email protected] (G)
*/

declare(strict_types=1);
Expand All @@ -30,6 +30,8 @@ class ToStd extends ToMemory implements Loggingable
{
/**
* List of allready flushed messages.
*
* @var array<string>
*/
public array $flushed = [];

Expand All @@ -48,7 +50,7 @@ class ToStd extends ToMemory implements Loggingable
/**
* Saves obejct instace (singleton...).
*/
private static $instance;
private static self $instance;

/**
* Logovací třída.
Expand All @@ -60,15 +62,7 @@ public function __construct($logName = null)
$this->logName = empty($logName) ? \Ease\Shared::appName() : $logName;
}

/**
* Pri vytvareni objektu pomoci funkce singleton (ma stejne parametry, jako
* konstruktor) se bude v ramci behu programu pouzivat pouze jedna jeho
* instance (ta prvni).
*
* @see http://docs.php.net/en/language.oop5.patterns.html Dokumentace a
* priklad
*/
public static function singleton()
public static function singleton(): self
{
if (!isset(self::$instance)) {
self::$instance = new self(\Ease\Shared::appName() ?: 'EaseFramework');
Expand Down
2 changes: 1 addition & 1 deletion src/Ease/Logger/ToSyslog.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ToSyslog extends ToStd implements Loggingable
/**
* Saves obejct instace (singleton...).
*/
private static $instance;
private static self $instance;

/**
* Logovací třída.
Expand Down
2 changes: 2 additions & 0 deletions src/Ease/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class Mailer extends Sand

/**
* Processed Headers.
*
* @var array<string, string>
*/
public array $mailHeadersDone = [];

Expand Down
6 changes: 3 additions & 3 deletions src/Ease/Shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Shared extends Atom
/**
* Array of Status Messages.
*
* @var array of Logger\Message
* @var array<Logger\Message> of Logger\Message
*/
public array $messages = [];

Expand Down Expand Up @@ -156,7 +156,7 @@ public static function cfg(/* string */ $constant, $cfg = null)
public static function appName()
{
if (method_exists('Composer\InstalledVersions', 'getRootPackage')) {
$package = \Composer\InstalledVersions::getRootPackage();
$package = InstalledVersions::getRootPackage();
} else {
$package['name'] = 'Unnamed';
}
Expand Down Expand Up @@ -328,7 +328,7 @@ 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<string,string> full configuration array
* @return array<string, string> full configuration array
*/
public function loadConfig(string $configFile, bool $defineConstants = false)
{
Expand Down
1 change: 1 addition & 0 deletions src/Ease/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class User extends Anonym

/**
* Store of user permissions.
*
* @var array<string, string>
*/
public array $permissions = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Ease/recordkey.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Record Key methods.
*
* @author Vítězslav Dvořák <[email protected]>
* @copyright 2019 [email protected] (G)
* @copyright 2019-2024 [email protected] (G)
*/

declare(strict_types=1);
Expand Down Expand Up @@ -48,7 +48,7 @@ abstract public function setDataValue(string $columnName, $value): bool;
/**
* Gives you value of KEY Column.
*
* @param array $data data z nichž se vrací hodnota klíče
* @param array<string, string> $data data z nichž se vrací hodnota klíče
*
* @return int key column value
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Ease/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FunctionsTest extends \PHPUnit\Framework\TestCase
public function testsysFilename(): void
{
if (strtoupper(substr(\PHP_OS, 0, 3)) === 'WIN') {
$this->assertContains(
$this->assertStringContainsString(
'\\\\',
Functions::sysFilename('/'),
_('Windows Files conversion'),
Expand Down Expand Up @@ -301,6 +301,6 @@ public function testclassesInNamespace(): void
*/
public function testguidv4(): void
{
$this->assertEquals('74657374-7465-4374-b465-737474657374', \Ease\Functions::guidv4('testtesttesttest'));
$this->assertEquals('74657374-7465-4374-b465-737474657374', Functions::guidv4('testtesttesttest'));
}
}

0 comments on commit b9d9e86

Please sign in to comment.