Skip to content

Conversation

@SebSept
Copy link
Contributor

@SebSept SebSept commented Oct 23, 2025

wip

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a developer documentation update.

Description

Comment on lines +134 to +135
$this->ensureKeyIsValid();
return file_get_contents($this->keyfile);
Copy link
Contributor

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.

Copy link
Contributor Author

@SebSept SebSept Oct 23, 2025

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.

Copy link
Contributor

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.

Copy link
Contributor Author

@SebSept SebSept Oct 23, 2025

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.

Comment on lines +57 to +58
$glpiNetwork = new self();
$glpiNetwork->showForConfig();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$glpiNetwork = new self();
$glpiNetwork->showForConfig();
self::showForConfig();

Copy link
Contributor Author

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 😆

Copy link
Contributor

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'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// $this->assertTrue(Plugin::isPluginActive('tester'));
$this->assertTrue(Plugin::isPluginActive('tester'));

Copy link
Contributor Author

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'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// $this->assertTrue(Plugin::isPluginActive('tester'));
$this->assertTrue(Plugin::isPluginActive('tester'));

Copy link
Contributor Author

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.

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