Skip to content

Sam 3 add phplinter and improve stan #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ pyvenv.cfg
.idea
.vscode
.vs

# Cache files
/runtime/

# Docker related files
Dockerfile
/docker/
docker-compose.yml
Makefile
231 changes: 122 additions & 109 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,115 +3,128 @@
use PhpCsFixer\Finder;
use PhpCsFixer\Config;

$finder = Finder::create()->in(__DIR__)
->exclude('docs');
$finder = Finder::create()
->exclude([
__DIR__ . '/docs/',
__DIR__ . '/vendor/',
])
->in(__DIR__)
->append([
__FILE__,
]);

$config = new Config();
$config
->setCacheFile(__DIR__ . '/runtime/.php-cs-fixer.cache')
->setRules(
[
'@PSR2' => true,
'@PHP84Migration' => true,
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'backtick_to_shell_exec' => true,
'binary_operator_spaces' => true,
'blank_lines_before_namespace' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => [
'break', 'case', 'continue', 'declare', 'default', 'do', 'for',
'if', 'foreach', 'return', 'switch', 'try', 'while',
],
],
'cast_spaces' => ['space' => 'single'],
'class_attributes_separation' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_type_declaration' => true,
'concat_space' => ['spacing' => 'one'],
'fully_qualified_strict_types' => true,
'increment_style' => ['style' => 'pre'],
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'native_function_casing' => true,
'native_type_declaration_casing' => true,
'new_with_parentheses' => true,
'no_alternative_syntax' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => ['use' => 'echo'],
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_superfluous_phpdoc_tags' => false,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_braces' => true,
'no_unset_cast' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'nullable_type_declaration_for_default_null_value' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => [
'order' => [
'use_trait', 'constant_public', 'constant_protected',
'constant_private', 'property_public_static', 'property_protected_static',
'property_private_static', 'property_public', 'property_protected',
'property_private', 'method_public_static', 'method_protected_static',
'method_private_static', 'construct', 'destruct', 'phpunit',
'method_public', 'method_protected', 'method_private', 'magic',
],
'sort_algorithm' => 'none',
],
'php_unit_fqcn_annotation' => true,
'php_unit_method_casing' => ['case' => 'camel_case'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
'phpdoc_align' => ['align' => 'left'],
'phpdoc_line_span' => [
'const' => 'multi',
'method' => 'multi',
'property' => 'multi',
],
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_to_comment' => false,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_var_without_name' => true,
'protected_to_private' => true,
'return_assignment' => false,
'return_type_declaration' => ['space_before' => 'one'],
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_quote' => true,
'single_line_comment_style' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'type_declaration_spaces' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
]
)->setFinder($finder);

return $config->setRules([
'@PSR2' => true,
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'backtick_to_shell_exec' => true,
'binary_operator_spaces' => true,
'blank_lines_before_namespace' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => [
'break', 'case', 'continue', 'declare', 'default', 'do', 'for',
'if', 'foreach', 'return', 'switch', 'try', 'while',
],
],
'cast_spaces' => ['space' => 'single'],
'class_attributes_separation' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'compact_nullable_type_declaration' => true,
'concat_space' => ['spacing' => 'one'],
'fully_qualified_strict_types' => true,
'increment_style' => ['style' => 'pre'],
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'magic_constant_casing' => true,
'magic_method_casing' => true,
'multiline_comment_opening_closing' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'native_function_casing' => true,
'native_type_declaration_casing' => true,
'new_with_parentheses' => true,
'no_alternative_syntax' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => ['use' => 'echo'],
'no_null_property_initialization' => true,
'no_short_bool_cast' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_superfluous_phpdoc_tags' => false,
'no_superfluous_elseif' => true,
'no_trailing_comma_in_singleline' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_braces' => true,
'no_unset_cast' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'nullable_type_declaration_for_default_null_value' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => [
'order' => [
'use_trait', 'constant_public', 'constant_protected',
'constant_private', 'property_public_static', 'property_protected_static',
'property_private_static', 'property_public', 'property_protected',
'property_private', 'method_public_static', 'method_protected_static',
'method_private_static', 'construct', 'destruct', 'phpunit',
'method_public', 'method_protected', 'method_private', 'magic',
],
'sort_algorithm' => 'none',
],
'php_unit_fqcn_annotation' => true,
'php_unit_method_casing' => ['case' => 'camel_case'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
'phpdoc_align' => ['align' => 'left'],
'phpdoc_line_span' => [
'const' => 'multi',
'method' => 'multi',
'property' => 'multi',
],
'phpdoc_no_access' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_to_comment' => false,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_var_without_name' => true,
'protected_to_private' => true,
'return_assignment' => false,
'return_type_declaration' => ['space_before' => 'one'],
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_quote' => true,
'single_line_comment_style' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'type_declaration_spaces' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
])->setFinder($finder);
return $config;
8 changes: 8 additions & 0 deletions .phplint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
path: ./
jobs: 10
cache-dir: runtime/.phplint.cache/
extensions:
- php
exclude:
- vendor/
- runtime/
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.73",
"phpbench/phpbench": "^1.0",
"overtrue/phplint": "^9.6.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
Expand Down Expand Up @@ -89,6 +90,7 @@
"@putenv PHP_CS_FIXER_IGNORE_ENV=1",
"php-cs-fixer fix --config=.php-cs-fixer.dist.php"
],
"phplint": "phplint",
"test": "phpunit"
},
"config": {
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ includes:
- phpstan-baseline.neon
parameters:
level: 8
phpVersion: 80400
fileExtensions:
- php
tmpDir: ./runtime/.phpstan/
paths:
- 'src'
- 'benchmarks'
Expand Down
2 changes: 1 addition & 1 deletion src/AnomalyDetectors/OneClassSVM.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct(
. "0 and 1, $nu given.");
}

$kernel = $kernel ?? new RBF();
$kernel ??= new RBF();

if ($tolerance < 0.0) {
throw new InvalidArgumentException('Tolerance must be,'
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/Amp.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(?int $workers = null)
. " must be greater than 0, $workers given.");
}

$workers = $workers ?? CPU::cores();
$workers ??= CPU::cores();

$this->pool = new DefaultPool($workers);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Classifiers/SVC.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function __construct(
. " than 0, $c given.");
}

$kernel = $kernel ?? new RBF();
$kernel ??= new RBF();

if ($tolerance < 0.0) {
throw new InvalidArgumentException('Tolerance must be'
Expand Down
2 changes: 1 addition & 1 deletion src/Clusterers/MeanShift.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static function estimateRadius(
. " between 0 and 100, $percentile given.");
}

$kernel = $kernel ?? new Euclidean();
$kernel ??= new Euclidean();

$samples = $dataset->samples();

Expand Down
10 changes: 5 additions & 5 deletions src/Helpers/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static function variance(array $values, ?float $mean = null) : float
throw new InvalidArgumentException('Variance is undefined for empty set.');
}

$mean = $mean ?? self::mean($values);
$mean ??= self::mean($values);

$ssd = 0.0;

Expand All @@ -195,7 +195,7 @@ public static function mad(array $values, ?float $median = null) : float
. ' is undefined for empty set.');
}

$median = $median ?? self::median($values);
$median ??= self::median($values);

$deviations = [];

Expand All @@ -220,7 +220,7 @@ public static function skewness(array $values, ?float $mean = null) : float
throw new InvalidArgumentException('Skewness is undefined for empty set.');
}

$mean = $mean ?? self::mean($values);
$mean ??= self::mean($values);

$numerator = self::centralMoment($values, 3, $mean);
$denominator = self::centralMoment($values, 2, $mean) ** 1.5;
Expand All @@ -242,7 +242,7 @@ public static function kurtosis(array $values, ?float $mean = null) : float
throw new InvalidArgumentException('Kurtosis is undefined for empty set.');
}

$mean = $mean ?? self::mean($values);
$mean ??= self::mean($values);

$numerator = self::centralMoment($values, 4, $mean);
$denominator = self::centralMoment($values, 2, $mean) ** 2;
Expand All @@ -269,7 +269,7 @@ public static function centralMoment(array $values, int $moment, ?float $mean =
throw new InvalidArgumentException('Moment cannot be less than 1.');
}

$mean = $mean ?? self::mean($values);
$mean ??= self::mean($values);

$sigma = 0.0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
* @author Andrew DalPino
* @author Aleksei Nechaev <[email protected]>
*/
interface Derivative {}
interface Derivative
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

interface IOBufferDerivative
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

interface OBufferDerivative
{

}
}
Loading