Skip to content

Commit

Permalink
Big code cleanning CS fixer php stan
Browse files Browse the repository at this point in the history
  • Loading branch information
instabledesign committed Dec 15, 2023
1 parent 4a699f4 commit 5daedfa
Show file tree
Hide file tree
Showing 40 changed files with 2,346 additions and 2,197 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[{*.php,*.json,*.md,*.html,*.css,*.js,*.yml}]
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
vendor
composer.lock
.phpunit.cache
.phpunit.result.cache
.php-cs-fixer.cache
25 changes: 25 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

$finder = (new PhpCsFixer\Finder())
->ignoreDotFiles(false)
->ignoreVCSIgnored(true)
->in(__DIR__)
;

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@PHP74Migration' => true,
'@PHP74Migration:risky' => true,
'@PHPUnit100Migration:risky' => true,
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' => true,
'yoda_style' => true,
'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']], // one should use PHPUnit built-in method instead
'modernize_strpos' => true, // needs PHP 8+ or polyfill
'no_useless_concat_operator' => false, // TODO switch back on when the `src/Console/Application.php` no longer needs the concat
])
->setFinder($finder)
;
106 changes: 55 additions & 51 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,58 @@
{
"name": "symftony/xpression",
"authors": [
{
"name": "Anthony",
"email": "[email protected]"
"name": "symftony/xpression",
"authors": [
{
"name": "Anthony",
"email": "[email protected]"
}
],
"type": "library",
"description": "Xpression is a simple PHP implementation of Specification pattern",
"keywords": [
"dsl",
"doctrine",
"orm",
"mongodb",
"collections",
"specification",
"expression",
"parser",
"lexer",
"query",
"builder",
"query builder"
],
"homepage": "https://github.com/symftony/Xpression",
"require": {
"php": "^8.0",
"doctrine/lexer": "^1.0"
},
"require-dev": {
"doctrine/collections": "^1.0",
"doctrine/orm": "^2.4.0",
"phpspec/prophecy": "^1.18",
"phpunit/phpunit": "^9.6",
"friendsofphp/php-cs-fixer": "^3.41",
"phpstan/phpstan": "^1.10"
},
"scripts": {
"test": "vendor/bin/phpunit",
"cs": "vendor/bin/php-cs-fixer fix",
"stan": "vendor/bin/phpstan analyse"
},
"suggest": {
"doctrine/collections": "If you want filter an ArrayCollection",
"doctrine/orm": "If you want filter an ORM query builder"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Symftony\\Xpression\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Symftony\\Xpression\\": "tests/"
}
}
],
"type": "library",
"description": "Xpression is a simple PHP implementation of Specification pattern",
"keywords": [
"dsl",
"doctrine",
"orm",
"mongodb",
"collections",
"specification",
"expression",
"parser",
"lexer",
"query",
"builder",
"query builder"
],
"homepage": "https://github.com/symftony/Xpression",
"require": {
"php": "^8.0",
"doctrine/lexer": "^1.0"
},
"require-dev": {
"doctrine/collections": "^1.0",
"doctrine/orm": "^2.4.0",
"phpspec/prophecy": "^1.18",
"phpunit/phpunit": "^9.6"
},
"scripts": {
"test": "vendor/bin/phpunit"
},
"suggest": {
"doctrine/collections": "If you want filter an ArrayCollection",
"doctrine/orm": "If you want filter an ORM query builder"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Symftony\\Xpression\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\Symftony\\Xpression\\": "tests/"
}
}
}
8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 6
paths:
- src
ignoreErrors:
- '/Method .*::(in|notIn|andX|nandX|orX|norX|xorX)\(\) has parameter .* with no value type specified in iterable type array\./'
- '/Method Symftony\\Xpression\\Parser::getNextToken\(\) return type has no value type specified in iterable type array\./'
- '/Method Symftony\\Xpression\\Lexer::get(Non)?CatchablePatterns\(\) return type has no value type specified in iterable type array\./'
23 changes: 11 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
convertNoticesToExceptions="true"
>
<coverage>
<include>
<directory>src</directory>
</include>
<exclude>
<directory>src/Exception</directory>
</exclude>
</coverage>
bootstrap="vendor/autoload.php">
<coverage/>
<php>
<ini name="error_reporting" value="-1"/>
</php>
Expand All @@ -23,4 +14,12 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
<exclude>
<directory>src/Exception</directory>
</exclude>
</source>
</phpunit>
53 changes: 26 additions & 27 deletions src/Bridge/Doctrine/Common/ExpressionBuilderAdapter.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

declare(strict_types=1);

namespace Symftony\Xpression\Bridge\Doctrine\Common;

use Doctrine\Common\Collections\ExpressionBuilder;
use Symftony\Xpression\Expr\ExpressionBuilderInterface;
use Symftony\Xpression\Exception\Expr\UnsupportedExpressionTypeException;
use Symftony\Xpression\Expr\ExpressionBuilderInterface;
use Symftony\Xpression\Lexer;

class ExpressionBuilderAdapter implements ExpressionBuilderInterface
{
private ExpressionBuilder $expressionBuilder;

public function __construct(ExpressionBuilder $expressionBuilder)
{
$this->expressionBuilder = $expressionBuilder;
}
public function __construct(
private ExpressionBuilder $expressionBuilder
) {}

public function getSupportedTokenType(): int
{
Expand All @@ -26,60 +25,60 @@ public function parameter(mixed $value, bool $isValue = false): mixed
return $value;
}

public function string($value): mixed
public function string(mixed $value): mixed
{
return $value;
}

public function isNull(string $field)
public function isNull(string $field): mixed
{
return $this->expressionBuilder->isNull($field);
}

public function eq(string $field, mixed $value)
public function eq(string $field, mixed $value): mixed
{
return $this->expressionBuilder->eq($field, $value);
}

public function neq(string $field, mixed $value)
public function neq(string $field, mixed $value): mixed
{
return $this->expressionBuilder->neq($field, $value);
}

public function gt(string $field, mixed $value)
public function gt(string $field, mixed $value): mixed
{
return $this->expressionBuilder->gt($field, $value);
}

public function gte(string $field, mixed $value)
public function gte(string $field, mixed $value): mixed
{
return $this->expressionBuilder->gte($field, $value);
}

public function lt(string $field, mixed $value)
public function lt(string $field, mixed $value): mixed
{
return $this->expressionBuilder->lt($field, $value);
}

public function lte(string $field, mixed $value)
public function lte(string $field, mixed $value): mixed
{
return $this->expressionBuilder->lte($field, $value);
}

public function in(string $field, array $values)
public function in(string $field, array $values): mixed
{
return $this->expressionBuilder->in($field, $values);
}

public function notIn(string $field, array $values)
public function notIn(string $field, array $values): mixed
{
return $this->expressionBuilder->notIn($field, $values);
}

/**
* /!\ Contains operator appear only in doctrine/common v1.1 /!\
* /!\ Contains operator appear only in doctrine/common v1.1 /!\.
*/
public function contains(string $field, mixed $value)
public function contains(string $field, mixed $value): mixed
{
if (!method_exists($this->expressionBuilder, 'contains')) {
throw new UnsupportedExpressionTypeException('contains');
Expand All @@ -88,32 +87,32 @@ public function contains(string $field, mixed $value)
return $this->expressionBuilder->contains($field, $value);
}

public function notContains(string $field, mixed $value)
public function notContains(string $field, mixed $value): mixed
{
throw new UnsupportedExpressionTypeException('notContains');
}

public function andX(array $expressions)
public function andX(array $expressions): mixed
{
return call_user_func_array([$this->expressionBuilder, 'andX'], $expressions);
return $this->expressionBuilder->andX(...$expressions);
}

public function nandX(array $expressions)
public function nandX(array $expressions): mixed
{
throw new UnsupportedExpressionTypeException('nandX');
}

public function orX(array $expressions)
public function orX(array $expressions): mixed
{
return call_user_func_array([$this->expressionBuilder, 'orX'], $expressions);
return $this->expressionBuilder->orX(...$expressions);
}

public function norX(array $expressions)
public function norX(array $expressions): mixed
{
throw new UnsupportedExpressionTypeException('norX');
}

public function xorX(array $expressions)
public function xorX(array $expressions): mixed
{
throw new UnsupportedExpressionTypeException('xorX');
}
Expand Down
Loading

0 comments on commit 5daedfa

Please sign in to comment.