-
-
Couldn't load subscription status.
- Fork 1.5k
Glpi key use exceptions not errors #21623
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
base: main
Are you sure you want to change the base?
Glpi key use exceptions not errors #21623
Conversation
| $this->ensureKeyIsValid(); | ||
| return file_get_contents($this->keyfile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes it read the key file twice every time it needs to perform an encrypt/decrypt. Should be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the downside of having 2 methods. The footprint of reading this local file et probably close to null. So I choose this approach (2 methods vs 1), it looks really better than having a single method that does both (checking key & show the message) and violate SRP principle.
Maybe we can have a local variable to keep the errors and avoid 2 calls to filegetcontents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are taking textbook concepts a bit too far here. The single purpose of the get method is to get the key. A part of that happens to be ensuring the key is valid, and that validation is only done here.
Indeed though, it probably doesn't make that much difference in this specific case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are taking textbook concepts a bit too far here. The single purpose of the get method is to get the key. A part of that happens to be ensuring the key is valid, and that validation is only done here.
Indeed though, it probably doesn't make that much difference in this specific case.
(Looks like my answer was lost)
That's not too far, that's the basis. Experience learnt me that's a very important point. Writing, reading, testing, maintaining, everything is easier respecting separation of concerns.
Only very strong reasons can justify not to respect it. I don't see any reason to do it here.
And we can use ensure method elsewhere in the future.
| $glpiNetwork = new self(); | ||
| $glpiNetwork->showForConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $glpiNetwork = new self(); | |
| $glpiNetwork->showForConfig(); | |
| self::showForConfig(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intented to have the less possible changes, but I can change it if it hurt your eyes 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only just because it is a static method and should be called statically.
| // Make sure the tester plugin is never deactived by a test as it would | ||
| // impact others tests that depend on it. | ||
| $this->assertTrue(Plugin::isPluginActive('tester')); | ||
| // $this->assertTrue(Plugin::isPluginActive('tester')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // $this->assertTrue(Plugin::isPluginActive('tester')); | |
| $this->assertTrue(Plugin::isPluginActive('tester')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, should not be committed. I'll fix it
| // Make sure the tester plugin is never deactived by a test as it would | ||
| // impact others tests that depend on it. | ||
| $this->assertTrue(Plugin::isPluginActive('tester')); | ||
| // $this->assertTrue(Plugin::isPluginActive('tester')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // $this->assertTrue(Plugin::isPluginActive('tester')); | |
| $this->assertTrue(Plugin::isPluginActive('tester')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not spent too much time reviewing, it's not ready yet.
wip
Checklist before requesting a review
Please delete options that are not relevant.
Description