Code-level changes #68
Replies: 4 comments
-
What to start with?
|
Beta Was this translation helpful? Give feedback.
-
The current CachePurgeInterface is probably okay, but I would avoid the abstract class and use a decorator instead, which is a bit more flexible. What about something like this?: <?php
class Purger implements CachePurgeInterface
{
private CachePurgeInterface $actual;
public configure(PurgerConfig $config) {
$this->actual = resolve($config->className);
$this->actual->configure($config);
}
public function purgeUrls(array $urls): bool {
// SOMETHING BEFORE
$result = $this->actual->purgeUrls($urls);
// SOMETHING AFTER
return $result;
}
public function purgeAll(array $urls): bool {
// SOMETHING BEFORE
$result = $this->actual->purgeAll();
// SOMETHING AFTER
return $result;
}
} |
Beta Was this translation helpful? Give feedback.
-
There is no need for CacheControlBehavior to be a Behavior. Instead, it could be a simple class that interacts with <?php
class CacheControl
{
public function __construct(private HeaderCollection $headers) {}
} |
Beta Was this translation helpful? Give feedback.
-
Design goals & principles
The Hollywood_principle / IoC
Relying on the Service Locator leads to spaghetto, because it makes it very easy to access everything from everywhere.
Only the main plugin class should be the glue between Craft and the code we own. As well our code should be designed with low coupling and clear separation of concerns in mind.
Tests
Writing tests should be fun! If it feels hard, most likely the principle above wasn't applied. Don't be afraid to change the actual code to make tests easier.
Each unit should be covered by tests, but don't be fanatic about 100% coverage.
Start with the happy path, but don't forget to cover edge cases.
Beta Was this translation helpful? Give feedback.
All reactions