Skip to content

Conversation

@LuigiCardamone
Copy link
Contributor

@LuigiCardamone LuigiCardamone commented Jan 13, 2023

This PR implements the feature described in this issue: #336

To skip the check you need to add this configuration:

return static function (Config $config): void {
    $config->setParseDocBlockCustomTags(false);
    //...
}

No breaking change is added: if the configuration is not modified the default behavior is used (ParseDocBlockCustomTags=true).

@LuigiCardamone LuigiCardamone force-pushed the skip_phpdoc_custom_tags branch 2 times, most recently from c55bc8b to e052afd Compare January 13, 2023 16:14
Copy link
Member

@AlessandroMinoccheri AlessandroMinoccheri left a comment

Choose a reason for hiding this comment

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

Can you please change the readme file documenting how to skip DocBlock Custom Tag detection ?

$customTag = str_replace('@', '', $tagValue->name);
$type = $this->resolveName(new Node\Name($customTag), Use_::TYPE_NORMAL);
$node->type = $type;
if ($this->parseDocBlockCustomTags) {

Choose a reason for hiding this comment

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

Is it possible to avoid another nested level?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! I also updated the docs.

@LuigiCardamone LuigiCardamone force-pushed the skip_phpdoc_custom_tags branch from e052afd to 637f0e1 Compare January 14, 2023 19:29
@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2023

Codecov Report

Merging #337 (102465a) into main (3c0eecc) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main     #337      +/-   ##
============================================
+ Coverage     93.99%   94.02%   +0.03%     
- Complexity      502      505       +3     
============================================
  Files            60       60              
  Lines          1365     1372       +7     
============================================
+ Hits           1283     1290       +7     
  Misses           82       82              
Impacted Files Coverage Δ
src/Analyzer/FileParserFactory.php 100.00% <100.00%> (ø)
src/Analyzer/NameResolver.php 77.91% <100.00%> (+0.13%) ⬆️
src/CLI/Config.php 95.45% <100.00%> (+1.70%) ⬆️
src/CLI/Runner.php 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@LuigiCardamone LuigiCardamone force-pushed the skip_phpdoc_custom_tags branch from 637f0e1 to 102465a Compare January 16, 2023 09:02
@LuigiCardamone
Copy link
Contributor Author

With my last commit I updated FileVisitorTest to solve a conflict with #335 and ConfigTest to increase test code coverage

@LuigiCardamone LuigiCardamone force-pushed the skip_phpdoc_custom_tags branch from 102465a to 9feb27c Compare January 18, 2023 08:38
Copy link
Member

@AlessandroMinoccheri AlessandroMinoccheri left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@AlessandroMinoccheri AlessandroMinoccheri added the enhancement New feature or request label Jan 18, 2023
@AlessandroMinoccheri AlessandroMinoccheri added this to the v1 milestone Jan 18, 2023
@micheleorselli
Copy link
Member

I am not sure if we should skip entirely the parsing of dependencies in a dobclock, since they are "soft" dependencies. What is your opinion on that?

If we stick to exclude only custom docblock may I suggest to change the name of the config method to make it more explicit? Something like $config->skipParsingAnnotations or $config->doNotParseAnnotations()

@LuigiCardamone
Copy link
Contributor Author

I am not sure if we should skip entirely the parsing of dependencies in a dobclock, since they are "soft" dependencies. What is your opinion on that?

If we stick to exclude only custom docblock may I suggest to change the name of the config method to make it more explicit? Something like $config->skipParsingAnnotations or $config->doNotParseAnnotations()

In my opinion with DocBlocks you can handle two complete different cases:

  1. Express the type of the variable:
    /**
     * @var QueryBuilder
     */
    private $foo;

that is just the legacy version of private QueryBuilder $foo.

  1. Give additional information about that variable:
    /**
     * @JMS\Expose
     */
    private string $foo;

The class may work event without that information (that is used outside).

I guess that violations about Case 1 are much more critical than Case 2. In our project we cannot easily remove dependency about Case 2. We need an option to skip violations of Case 2 (like @JMS\Expose and similar).

How would you call such an option?
I used the term "customTag" since a $customTag variable was already used in NameResolver.php.
I am afraid that skipParsingAnnotations can be misleading with Case 1. What about skipParsingCustomAnnotations or parseOnlyTypingAnnotations?

@micheleorselli
Copy link
Member

ok, let's keep the current PR behaviour. regarding the name skipParsingCustomAnnotations sounds fine to me

@LuigiCardamone LuigiCardamone force-pushed the skip_phpdoc_custom_tags branch from 9feb27c to 5afd713 Compare January 20, 2023 14:52
@LuigiCardamone
Copy link
Contributor Author

ok, let's keep the current PR behaviour. regarding the name skipParsingCustomAnnotations sounds fine to me

@micheleorselli I just updated the code, the test and the documentation.

The GitHub check that failed is for something not related to this issue: "Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 7.1.33-51+ubuntu20.04.1+deb.sury.org+1, please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting."

@AlessandroMinoccheri
Copy link
Member

@LuigiCardamone it's Github/composer issue, I run actions, and now it's totally green.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants