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

Sniff to limit the use of new in constructor #153

Merged
merged 12 commits into from
Feb 3, 2022

Conversation

kevin-schmitt
Copy link
Contributor

@kevin-schmitt kevin-schmitt commented Jan 26, 2022

see #25
Thanks in adavnce for reviewing :)
Im not sure for typo use NewInstanceSniff is good ? else i think NewKeywordInstanceSniff ?

@codecov
Copy link

codecov bot commented Jan 26, 2022

Codecov Report

Merging #153 (3871d5c) into master (f4c215f) will increase coverage by 0.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #153      +/-   ##
============================================
+ Coverage     97.41%   97.61%   +0.20%     
- Complexity      136      149      +13     
============================================
  Files            16       17       +1     
  Lines           348      378      +30     
============================================
+ Hits            339      369      +30     
  Misses            9        9              
Impacted Files Coverage Δ
src/Codor/Sniffs/Classes/NewInstanceSniff.php 100.00% <100.00%> (ø)

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 f4c215f...3871d5c. Read the comment docs.

README.md Show resolved Hide resolved
@villfa
Copy link
Collaborator

villfa commented Jan 26, 2022

I think more tests are required.

Check there is no warning in this case:

<?php

$app = new Application();
$app->run();

Does it work with regular functions?

<?php

function newClass(): Class
{
    return new Class();
}

What about anonymous classes? Maybe we should ignore them.

@villfa
Copy link
Collaborator

villfa commented Jan 29, 2022

Since PHP 8.1 new is also allowed in the constructors parameters: https://3v4l.org/SmdWR#v8.1.2
We need a test to be sure there won't be any warnings in this case.

@kevin-schmitt
Copy link
Contributor Author

Thanks @villfa ,

I add some tests and case
I add handle for case not work like scope_opener not present but is a function
I fix various things

Not simple to implement ^^

Can you review me please ?
What is codecov patch and project ? problem with that how i can resolve please ?

Thanks

Copy link
Collaborator

@villfa villfa left a comment

Choose a reason for hiding this comment

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

Great work! :)

I've added just 2 last comments but otherwise it seems ready to merge.

FYI Codecov is a tool checking that the code coverage is always improving.
It complains because of one line not being tested:
Screenshot 2022-02-02 at 17 18 24
If you think of a way to test it then go ahead, otherwise it's ok to let it as it is.

README.md Outdated Show resolved Hide resolved
src/Codor/Sniffs/Classes/NewInstanceSniff.php Show resolved Hide resolved
@villfa villfa merged commit bf8a3b2 into bmitch:master Feb 3, 2022
@villfa
Copy link
Collaborator

villfa commented Feb 3, 2022

Thank you :)

@kevin-schmitt kevin-schmitt deleted the feat/sniff-new-keyword-instance branch February 4, 2022 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants