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

Allow app check code for deprecated classes #16935

Merged
merged 12 commits into from
Jul 20, 2015

Conversation

nickvergessen
Copy link
Contributor

Old behaviour (without parameter):

nickv@nickv-think ~/ownCloud/master/core $ ./occ app:check-code activity
App is compliant - awesome job!

With deprecated parameter:

nickv@nickv-think ~/ownCloud/master/core $ ./occ app:check-code activity --deprecated
Analysing /home/nickv/ownCloud/master/repos/activity/templates/stream.app.navigation.php
 1 errors
    line   14: == - is discouraged
Analysing /home/nickv/ownCloud/master/repos/activity/controller/settings.php
 2 errors
    line   31: OCP\IConfig - deprecated class must not be imported with a use statement
    line  112: == - is discouraged
Analysing /home/nickv/ownCloud/master/repos/activity/lib/data.php
 1 errors
    line   27: OCP\DB - deprecated class must not be imported with a use statement

Analysing /home/nickv/ownCloud/master/repos/activity/appinfo/update.php
 3 errors
    line   14: OCP\DB - Static method of deprecated class must not be called
    line   24: OCP\DB - Static method of deprecated class must not be called
    line   26: OCP\DB - Static method of deprecated class must not be called
App uses deprecated functionality

Requested at https://mailman.owncloud.org/pipermail/devel/2015-June/001301.html

I think it's quite useful.
Also fixing a bug (use statements could circumvent blacklisted classes)

@DeepDiver1975 @MorrisJobke @LukasReschke

Todo

  • Add support for deprecated classes
  • Add support for deprecated constants
  • Add support for deprecated functions
  • Add support for deprecated methods

@DeepDiver1975 DeepDiver1975 added this to the 8.2-next milestone Jun 15, 2015
@rullzer
Copy link
Contributor

rullzer commented Jul 5, 2015

Awesome work.
We should also try to get a checker for out internal code. To make sure non deprecated functions/methods do not call deprecated functions/methods..

@PVince81
Copy link
Contributor

PVince81 commented Jul 6, 2015

Needs rebase

@DeepDiver1975
Copy link
Member

@nickvergessen please rebase an let's move this in - THX

@nickvergessen
Copy link
Contributor Author

Btw, does anyone know something that got deprecated in the last 21days?

@nickvergessen nickvergessen force-pushed the allow-app-check-code-for-deprecated-classes branch from faef8de to ee7dd54 Compare July 6, 2015 13:22
@DeepDiver1975
Copy link
Member

Btw, does anyone know something that got deprecated in the last 21days?

Not that I'm aware of

@nickvergessen
Copy link
Contributor Author

Rebased and added the open task as todo.

Should be okay to merge, it doesn't catch everything, but at least static methods are done.

);
}

protected function execute(InputInterface $input, OutputInterface $output) {
$appId = $input->getArgument('app-id');
$codeChecker = new \OC\App\CodeChecker();
if ($input->getOption('deprecated')) {
$codeChecker = new DeprecationCodeChecker();
Copy link
Member

Choose a reason for hiding this comment

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

I would highly recommend use of the Decorator pattern here, instead of subclassing CodeChecker with the desired functionality. It means that if we introduce some other functionality at a later point, we just re-wrap the CodeChecker instead of needing 6 (!!!) subclasses. It quickly spirals out of control after that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

/me wraps Xenopathic into a decorator....

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

@nickvergessen nickvergessen force-pushed the allow-app-check-code-for-deprecated-classes branch from ee7dd54 to 6b35a60 Compare July 7, 2015 10:18
if ($input->getOption('deprecated')) {
$list = new DeprecationList();
} else {
$list = new PrivateList();
Copy link
Member

Choose a reason for hiding this comment

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

🙈 This isn't actually the Decorator pattern... What happens if we introduce some more checking, that we might need to combine with DeprecationList and/or PrivateList? You have the same problem, needing many classes and subclasses to cover all possibilities.

Have a BasicList class, whose methods return empty arrays, then let DeprecationList and PrivateList take an ICheckList in the constructor, and forward the methods to that wrapped ICheckList. Then you create a list at the start ($list = new BasicList()), then if we want to test for deprecation replace the object with the wrapped DeprecationList ($list = new DeprecationList($list)), etc for all features.

Sorry to be such a pain, but I can see this needing a refactor in the (near?) future if it isn't done now. 🙊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, mixed it up a bit. Should be fixed now

@RobinMcCorkell
Copy link
Member

Nice! Any reason why it's DeprecatedCheck or PrivateCheck? Can we not have PrivateCheck enabled by default (controllable by a new parameter would be cool) and enable DeprecatedCheck as well if the option is set? Or was the intention to do this?

I can see ./occ app:check-code --deprecated --no-private --check-foobar being really powerful when the app checker gets more features...

@rullzer
Copy link
Contributor

rullzer commented Jul 8, 2015

I agree with @Xenopathic lets enable the extra checks by default.
Programmers are lazy so better enable as much by default as possible.

@nickvergessen
Copy link
Contributor Author

My idea was to be able to fail travis on private class usage and make travis "allow failure" for deprecated usage... so as long as it is possible to do those two separatly I'm fine with it

@RobinMcCorkell
Copy link
Member

@nickvergessen May I push to this branch? I'll implement the selectable features thing I mentioned above if you want 😄

@MorrisJobke
Copy link
Contributor

@Xenopathic Do it. @nickvergessen is usually on vacation right now :P

@RobinMcCorkell
Copy link
Member

You can now specify the checkers you want enabled, with --checker=... or -c.... So to only enable private class and strong comparison checks, use ./occ app:check-code -cprivate -cstrong-comparison. By default, all are enabled, so we need to tell Jenkins to only use the private checker at the moment.

@MorrisJobke
Copy link
Contributor

Analysing /home/mjob/Projekte/owncloud/master/apps2/music/app/music.php
 1 errors
    line  236: OCP\User::getUser - Method of deprecated private class must not be called
Analysing /home/mjob/Projekte/owncloud/master/apps2/music/middleware/ampachemiddleware.php
 1 errors
    line   71: OC_Util - Static method of deprecated private class must not be called
  • OCP\User is not a private class, but is correctly deprecated.
  • OC_Utilprivate and deprecated

@RobinMcCorkell
Copy link
Member

@MorrisJobke Ah, that's a side effect of the description concatenation. If both DeprecationCheck and PrivateCheck are enabled, any failures will be marked as deprecated private class, regardless of which checker actually found the error.

@MorrisJobke
Copy link
Contributor

@Xenopathic Can we fix this?

@RobinMcCorkell
Copy link
Member

@MorrisJobke I have an idea...

'checker',
'c',
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'enable the specified checker',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this is what people see as help, we should maybe add the available checkers here?

Copy link
Member

Choose a reason for hiding this comment

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

The help text displays the default value, which is currently all the available checkers (all are enabled by default). If we include some non-default-on checkers later in the future, this could become an issue. The problem is, if we list all the checkers here, the default also gets displayed, so you will see the checkers twice (not to mention the help text line will be really long)

This is the help text:

--checker (-c)        enable the specified checker (default: ["private","deprecation","strong-comparison"]) (multiple values allowed)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah right, I didn't check the output. Seems okay when they output the default value.
Now the question is should we include all in the default (and I think we shouldn't, but private only)?

@nickvergessen
Copy link
Contributor Author

Well, that is why I wouldn't add them all by default...
Will have a look whether I can find a way later.

@nickvergessen
Copy link
Contributor Author

#17046 was merged, so I will add that when jenkins reported back

@nickvergessen nickvergessen force-pushed the allow-app-check-code-for-deprecated-classes branch from d05ecba to 3566dcf Compare July 17, 2015 10:35
@scrutinizer-notifier
Copy link

A new inspection was created.

@nickvergessen
Copy link
Contributor Author

Rebased to fix the oracle thing without timeout.

@MorrisJobke
Copy link
Contributor

Jenkins PR #17720

@MorrisJobke
Copy link
Contributor

Tested and works nicely 👍

@nickvergessen
Copy link
Contributor Author

@Xenopathic want to review? ;)

@RobinMcCorkell
Copy link
Member

Code looks good, haven't tested it however. 👍

nickvergessen added a commit that referenced this pull request Jul 20, 2015
…ecated-classes

Allow app check code for deprecated classes
@nickvergessen nickvergessen merged commit 0dd1a78 into master Jul 20, 2015
@nickvergessen nickvergessen deleted the allow-app-check-code-for-deprecated-classes branch July 20, 2015 06:39
@oparoz
Copy link
Contributor

oparoz commented Oct 4, 2015

You can now specify the checkers you want enabled, with --checker=... or -c.... So to only enable private class and strong comparison checks, use ./occ app:check-code -cprivate -cstrong-comparison. By default, all are enabled, so we need to tell Jenkins to only use the private checker at the moment.

Documentation/OP needs to be updated. It still has the old switch, which doesn't work and no explanation on the other valid options

@nickvergessen
Copy link
Contributor Author

@oparoz posted in the docs repo: owncloud-archive/documentation#1736

@oparoz
Copy link
Contributor

oparoz commented Oct 5, 2015

Thanks. Added a link to the doc from the list of features for 8.2.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants