Skip to content

Added DNF type support#505

Draft
krzysztof-ciszewski wants to merge 1 commit intogoaop:masterfrom
krzysztof-ciszewski:feat-dnf-types
Draft

Added DNF type support#505
krzysztof-ciszewski wants to merge 1 commit intogoaop:masterfrom
krzysztof-ciszewski:feat-dnf-types

Conversation

@krzysztof-ciszewski
Copy link
Copy Markdown

TODO:

  • tests
  • domain exceptions

@scrutinizer-notifier
Copy link
Copy Markdown

A new inspection was created.

@krzysztof-ciszewski krzysztof-ciszewski marked this pull request as draft May 19, 2024 14:59
$pointcuts = array_slice($args, 1);
}

if (count(array_filter($pointcuts, static fn ($pointcut) => $pointcut instanceof Pointcut)) !== count($pointcuts)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before opening parenthesis of function call prohibited

@@ -0,0 +1,14 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

readonly class Node
{
public function __construct(
public NodeType $type,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

{
public function __construct(
public NodeType $type,
public ?string $identifier = null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

public function __construct(
public NodeType $type,
public ?string $identifier = null,
public ?Node $left = null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

public NodeType $type,
public ?string $identifier = null,
public ?Node $left = null,
public ?Node $right = null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8

@@ -0,0 +1,10 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

enum NodeType
{
case IDENTIFIER;
case AND;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

{
case IDENTIFIER;
case AND;
case OR;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR

@@ -0,0 +1,13 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

case IDENTIFIER;
case LPAREN;
case RPAREN;
case AND;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

case LPAREN;
case RPAREN;
case AND;
case OR;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR

@@ -0,0 +1,74 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

@@ -0,0 +1,74 @@
<?php

namespace Go\Aop\Pointcut\DNF\Parser;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be one blank line after the namespace declaration

* @param \ArrayIterator<\PhpToken> $tokens
*/
public function __construct(
private readonly \ArrayIterator $tokens
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 4 spaces, found 8


private function getToken(string $val): Token
{
return match ($val) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before opening parenthesis of function call prohibited

chr(26) => Token::EOF,
'(' => Token::LPAREN,
')' => Token::RPAREN,
'|' => Token::OR,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR

'(' => Token::LPAREN,
')' => Token::RPAREN,
'|' => Token::OR,
'&' => Token::AND,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

')' => Token::RPAREN,
'|' => Token::OR,
'&' => Token::AND,
default => Token::IDENTIFIER
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 8 spaces, found 12

@@ -0,0 +1,21 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

* @return array{0: Token, 1: string|null}
*/
public function peek(int $i): array;
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 newline at end of file; 0 found

@@ -0,0 +1,113 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

TokenCollection $tokens,
int $bindingPower,
bool $insideParenthesis = false
): ?Node {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration; found 0 spaces

): ?Node {
[$token, $val] = $tokens->next();
switch ($token) {
case Token::LPAREN:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CASE statements must be defined using a colon

while (true) {
[$token] = $tokens->peek(0);

if ($token === Token::OR && $insideParenthesis) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR

}

switch ($token) {
case Token::OR:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR


switch ($token) {
case Token::OR:
case Token::AND:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND


private function operatorNode(Token $type, Node $left, ?Node $right): Node
{
return match ($type) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before opening parenthesis of function call prohibited

private function operatorNode(Token $type, Node $left, ?Node $right): Node
{
return match ($type) {
Token::OR => new Node(NodeType::OR, left: $left, right: $right),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR

{
return match ($type) {
Token::OR => new Node(NodeType::OR, left: $left, right: $right),
Token::AND => new Node(NodeType::AND, left: $left, right: $right),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

return match ($type) {
Token::OR => new Node(NodeType::OR, left: $left, right: $right),
Token::AND => new Node(NodeType::AND, left: $left, right: $right),
default => throw new Exception('invalid op')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 8 spaces, found 12

*/
private function getBindingPower(Token $type): array
{
return match ($type) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before opening parenthesis of function call prohibited

private function getBindingPower(Token $type): array
{
return match ($type) {
Token::OR => [1, 2],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR

{
return match ($type) {
Token::OR => [1, 2],
Token::AND => [3, 4],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

return match ($type) {
Token::OR => [1, 2],
Token::AND => [3, 4],
default => throw new Exception('Invalid operator')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 8 spaces, found 12

};
}

} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Expected 1 newline at end of file; 0 found
  • The closing brace for the class must go on the next line after the body

@@ -0,0 +1,8 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

interface TokenizerParserInterface
{
public function parse(string $input);
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 newline at end of file; 0 found

@@ -0,0 +1,44 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

|| $val->implementsInterface($tree->identifier);
}

if ($tree?->type === NodeType::AND) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

return match ($type) {
Token::OR => new Node(NodeType::OR, left: $left, right: $right),
Token::AND => new Node(NodeType::AND, left: $left, right: $right),
default => throw new Exception('invalid op')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 8 spaces, found 12

*/
private function getBindingPower(Token $type): array
{
return match ($type) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before opening parenthesis of function call prohibited

private function getBindingPower(Token $type): array
{
return match ($type) {
Token::OR => [1, 2],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR

{
return match ($type) {
Token::OR => [1, 2],
Token::AND => [3, 4],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

return match ($type) {
Token::OR => [1, 2],
Token::AND => [3, 4],
default => throw new Exception('Invalid operator')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line indented incorrectly; expected 8 spaces, found 12

};
}

} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Expected 1 newline at end of file; 0 found
  • The closing brace for the class must go on the next line after the body

@@ -0,0 +1,8 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

interface TokenizerParserInterface
{
public function parse(string $input);
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 newline at end of file; 0 found

@@ -0,0 +1,44 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

|| $val->implementsInterface($tree->identifier);
}

if ($tree?->type === NodeType::AND) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected and but found AND

return $this->verifyTree($tree->left, $val) && $this->verifyTree($tree->right, $val);
}

if ($tree->type === NodeType::OR) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP keywords must be lowercase; expected or but found OR


return $parentClasses;
}
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 newline at end of file; 0 found

@@ -0,0 +1,11 @@
<?php
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End of line character is invalid; expected \n but found \r\n

interface SemanticAnalyzerInterface
{
public function verifyTree(Node $tree, \ReflectionClass|ReflectionFileNamespace $val);
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 newline at end of file; 0 found

->call(fn($parentClassName) => new ClassInheritancePointcut($parentClassName))
->call(static function (...$args) {
return array_map(
static fn (string $class) => new ClassInheritancePointcut($class),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Line indented incorrectly; expected 16 spaces, found 20
  • Space before opening parenthesis of function call prohibited

->call($stringConverter)
->is('namespacePattern', '&', 'namespacePattern')
->call($stringConverter)
->is('(' , 'namespacePattern', '&', 'namespacePattern', ')')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space found before comma in function call

@krzysztof-ciszewski
Copy link
Copy Markdown
Author

@lisachenko I would suggest disabling nitpick, seems pretty outdated, most of these comments are wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants