Skip to content
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

Refactor directives to value objects for full power of new IDE usab. #149

Merged
merged 5 commits into from
Oct 30, 2019

Conversation

dereuromark
Copy link
Owner

@dereuromark dereuromark commented Oct 22, 2019

Prepare release 0.14 here as major for

to get constraint with new minors here.

Resolves #114
Now allows using pretty soon full spectrum of https://blog.jetbrains.com/phpstorm/2019/02/new-phpstorm-meta-php-features/
thanks to value object approach now.

Available directives

Override

By default, most directives used here are "override". Those are also the ones already supported the longest.
For specific string method argument it returns a specific object. That covers a lot of CakePHP's internal magic.

$method = '\Namespace\PackageName\MyFactory::create(0)';
$map = [
    'alpha' => '\My\Cool\Alpha::class',
    'beta' => '\My\Cool\Beta::class',
];
$directive = new Override($method, $map);
ExpectedArguments

With this you can set default values to chose from for method arguments.
Specify the parameter count as 0-based value.

$method = '\Namespace\PackageName\MyFactory::create()';
$position = 0; 
$list = [
    'alpha',
    'beta',
];
$directive = new ExpectedArguments($method, $position, $list);
ExpectedReturnValues

You can also just expected return types for a method.

$method = '\Namespace\PackageName\MyFactory::create()';
$list = [
    '\My\Cool\Alpha::class',
    '\My\Cool\Beta::class',
];
$directive = new ExpectedReturnValues($method, $list);
RegisterArgumentsSet

If you are reusing the same lists for both arguments and return values, you can also
make a set and reuse that in the above directives.

$set = 'mySet';
$list = [
    '\My\Cool\Class::SUCCESS',
    '\My\Cool\Class::ERROR',
];
$directive = new RegisterArgumentsSet($set, $list);

Now you can use it as list value argumentsSet("mySet") inside the others.

Nesting
$list = [
    '\My\Cool\Class::SUCCESS',
    '\My\Cool\Class::ERROR',
];
$argumentsSet = new RegisterArgumentsSet('mySet', $list);

$method = '\Namespace\PackageName\MyFactory::create()';
$list = [
    $argumentsSet,
];
$expectedReturnValues = new ExpectedReturnValues($method, $list);

Examples

Validator::requirePresence()

validation_autocomplete_validator_require_presence

Now not just bool true/false, but also the possible "magic strings" are typehinted and usable as single click/enter.

@codecov-io
Copy link

codecov-io commented Oct 22, 2019

Codecov Report

Merging #149 into master will decrease coverage by 0.23%.
The diff coverage is 88.49%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #149      +/-   ##
============================================
- Coverage     88.88%   88.64%   -0.24%     
- Complexity     1099     1129      +30     
============================================
  Files            57       63       +6     
  Lines          2923     3022      +99     
============================================
+ Hits           2598     2679      +81     
- Misses          325      343      +18
Impacted Files Coverage Δ Complexity Δ
src/Generator/TaskCollection.php 83.87% <ø> (ø) 12 <0> (ø) ⬇️
src/Generator/PhpstormGenerator.php 70.58% <100%> (-29.42%) 6 <0> (ø)
src/Generator/Task/HelperTask.php 97.14% <100%> (+0.08%) 12 <0> (ø) ⬇️
src/Generator/Task/ComponentTask.php 97.14% <100%> (+0.08%) 12 <0> (ø) ⬇️
src/Generator/Task/DatabaseTypeTask.php 89.47% <100%> (+1.23%) 5 <0> (ø) ⬇️
src/Generator/Directive/ExpectedArguments.php 100% <100%> (ø) 4 <4> (?)
src/Generator/Task/PluginTask.php 100% <100%> (ø) 4 <0> (ø) ⬇️
src/Generator/Task/ModelTask.php 92.5% <100%> (+0.19%) 14 <0> (ø) ⬇️
src/Generator/Task/TableFinderTask.php 88% <100%> (+0.32%) 23 <0> (ø) ⬇️
src/Generator/Task/TableAssociationTask.php 100% <100%> (ø) 3 <0> (ø) ⬇️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 400287c...d5e7b10. Read the comment docs.

@Spriz
Copy link

Spriz commented Oct 24, 2019

This is amazing magic @dereuromark - will update it and use it in my daily work :) Will report back any issues, if any :)

@dereuromark dereuromark merged commit b32c3d9 into master Oct 30, 2019
@dereuromark dereuromark deleted the feature/directive branch October 30, 2019 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test new phpstorm meta
3 participants