phpan/phpstan checks and fixes

This commit is contained in:
Clemens Schwaighofer
2022-01-13 16:11:19 +09:00
parent 13c0fcd869
commit 1bd45d8a8a
9 changed files with 97 additions and 23 deletions

0
4dev/checking/phan.sh Normal file → Executable file
View File

0
4dev/checking/phpstan.sh Normal file → Executable file
View File

View File

@@ -13,12 +13,81 @@ use PHPUnit\Framework\TestCase;
*/
final class CoreLibsDebugLoggingTest extends TestCase
{
public $log;
public function optionsProvider(): array
{
return [
'log folder set' => [
[
'log_folder' => '/tmp'
],
[
'log_folder' => '/tmp/'
],
[]
],
'nothing set' => [
null,
[
'log_folder' => getcwd() . DIRECTORY_SEPARATOR
],
[]
],
'no options set, constant set' => [
null,
[
'log_folder' => '/tmp/'
],
[
'constant' => [
'BASE' => '/tmp',
'LOG' => '/'
]
]
],
];
}
// init tests
// - __construct call with options
/**
* Undocumented function
*
* @dataProvider optionsProvider
* @testdox init test [$_dataName]
*
* @param array|null $options
* @param array $expected
* @param array $override
* @return void
*/
public function testClassInit(?array $options, array $expected, array $override): void
{
if (!empty($override['constant'])) {
foreach ($override['constant'] as $var => $value) {
define($var, $value);
}
}
if ($options === null) {
$this->log = new \CoreLibs\Debug\Logging();
} else {
$this->log = new \CoreLibs\Debug\Logging($options);
}
// check that settings match
// print "LOG: " . $this->log->getSetting('log_folder') . "\n";
$this->assertEquals(
$expected['log_folder'],
$this->log->getSetting('log_folder')
);
}
// setting tests
// - basicSetLogId
// - getLogLevelAll
// - getLogId
// - setLogLevelAll
// - getLogLevelAll
// - debugFor
// - setLogLevel
// - getLogLevel

View File

@@ -30,16 +30,21 @@ The old non namepsace format layout.
This is fully deprecated and will no longer be maintaned.
last tested PHP 5.6 and PHP 7.0
### namespace
### development
The new namespace branch. This is the development area for the master branch
Any current development is done here
## Static checks
With phpstan
With phpstan (`4dev/checking/phpstan.sh`)
`phpstan`
With phan
With phan (`4dev/checking/phan.sh`)
`phan --progress-bar -C --analyze-twice`
pslam is setup but not configured
## Unit tests
With phpunit (`4dev/checking/phpunit.sh`)
`phpunit -c $phpunit.xml 4dev/tests/`

View File

@@ -29,12 +29,11 @@ if (!defined('SET_SESSION_NAME')) {
$LOG_FILE_ID = 'classTest-json';
ob_end_flush();
use CoreLibs\Check\Json;
// use CoreLibs\Check\Jason;
use CoreLibs\Convert\Json;
use CoreLibs\Debug\Support as DgS;
$basic = new CoreLibs\Basic();
$json_class = 'CoreLibs\Check\Json';
$json_class = 'CoreLibs\Convert\Json';
// define a list of from to color sets for conversion test

View File

@@ -1238,10 +1238,10 @@ class Basic
* @param int $green green 0-255
* @param int $blue blue 0-255
* @param bool $hex_prefix default true, prefix with "#"
* @return string rgb in hex values with leading # if set
* @return string|bool rgb in hex values with leading # if set
* @deprecated use \CoreLibs\Convert\Colors::rgb2hex() instead
*/
public static function rgb2hex(int $red, int $green, int $blue, bool $hex_prefix = true): string
public static function rgb2hex(int $red, int $green, int $blue, bool $hex_prefix = true)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::rgb2hex($red, $green, $blue, $hex_prefix);
@@ -1252,10 +1252,10 @@ class Basic
* @param int $red red 0-255
* @param int $green green 0-255
* @param int $blue blue 0-255
* @return string hex rgb string
* @return string|bool hex rgb string
* @deprecated use rgb2hex instead
*/
public static function rgb2html(int $red, int $green, int $blue): string
public static function rgb2html(int $red, int $green, int $blue)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
// check that each color is between 0 and 255
@@ -1269,10 +1269,10 @@ class Basic
* @param int $red red 0-255
* @param int $green green 0-255
* @param int $blue blue 0-255
* @return array<mixed> Hue, Sat, Brightness/Value
* @return array<mixed>|bool Hue, Sat, Brightness/Value
* @deprecated use \CoreLibs\Convert\Colors::rgb2hsb() instead
*/
public static function rgb2hsb(int $red, int $green, int $blue): array
public static function rgb2hsb(int $red, int $green, int $blue)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsb()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::rgb2hsb($red, $green, $blue);
@@ -1283,10 +1283,10 @@ class Basic
* @param int $H hue 0-360
* @param float $S saturation 0-1 (float)
* @param float $V brightness/value 0-1 (float)
* @return array<mixed> 0 red/1 green/2 blue array
* @return array<mixed>|bool 0 red/1 green/2 blue array
* @deprecated use \CoreLibs\Convert\Colors::hsb2rgb() instead
*/
public static function hsb2rgb(int $H, float $S, float $V): array
public static function hsb2rgb(int $H, float $S, float $V)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hsb2rgb()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::hsb2rgb($H, (int)round($S * 100), (int)round($V * 100));
@@ -1299,10 +1299,10 @@ class Basic
* @param int $r red 0-255
* @param int $g green 0-255
* @param int $b blue 0-255
* @return array<mixed> hue/sat/luminance
* @return array<mixed>|bool hue/sat/luminance
* @deprecated use \CoreLibs\Convert\Colors::rgb2hsl() instead
*/
public static function rgb2hsl(int $r, int $g, int $b): array
public static function rgb2hsl(int $r, int $g, int $b)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsl()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::rgb2hsb($r, $g, $b);
@@ -1313,10 +1313,10 @@ class Basic
* @param int $h hue: 0-360 (degrees)
* @param float $s saturation: 0-1
* @param float $l luminance: 0-1
* @return array<mixed> red/blue/green 0-255 each
* @return array<mixed>|bool red/blue/green 0-255 each
* @deprecated use \CoreLibs\Convert\Colors::hsl2rgb() instead
*/
public static function hsl2rgb(int $h, float $s, float $l): array
public static function hsl2rgb(int $h, float $s, float $l)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hsl2rgb()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::hsl2rgb($h, $s * 100, $l * 100);

View File

@@ -330,6 +330,7 @@ class ArrayHandler
/**
* will loop through an array recursivly and write the array keys back
* @param array<mixed> $array multidemnsional array to flatten
* @param array<mixed> $return recoursive pass on array of keys
* @return array<mixed> flattened keys array
*/
public static function flattenArrayKey(array $array, array $return = []): array

View File

@@ -60,7 +60,7 @@ class Uids
// fallback to this hash type
$hash = self::FALLBACK_HASH;
if (
defined('DEFAULT_HASH') && !empty(DEFAULT_HASH) &&
defined('DEFAULT_HASH') &&
in_array(DEFAULT_HASH, hash_algos())
) {
$hash = DEFAULT_HASH;

View File

@@ -13,6 +13,7 @@ class FileWriter
{
/** @var string */
private static $debug_filename = 'debug_file.log'; // where to write output
/** @var string */
private static $debug_folder;
/**
@@ -71,8 +72,7 @@ class FileWriter
// if empty try to set base log folder
if (
empty(self::$debug_folder) &&
defined('BASE') && !empty(BASE) &&
defined('LOG') && !empty(LOG)
defined('BASE') && defined('LOG')
) {
self::$debug_folder = BASE . LOG;
}