From 6563cb0c4030e820bfbc70fae5317bcae3b259f4 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 15:27:45 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/Collections/CachedConfigCollection.php | 6 +++--- src/Collections/DeltaConfigCollection.php | 12 ++++++------ src/Transformer/YamlTransformer.php | 22 +++++++++++----------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Collections/CachedConfigCollection.php b/src/Collections/CachedConfigCollection.php index 4fcfb71..008a7b6 100644 --- a/src/Collections/CachedConfigCollection.php +++ b/src/Collections/CachedConfigCollection.php @@ -132,7 +132,7 @@ public function getCollection() // Load from cache (unless flushing) if (!$this->flush) { - $this->collection = $this->cache->get(self::CACHE_KEY); + $this->collection = $this->cache->get(CachedConfigCollection::CACHE_KEY); if ($this->collection) { $this->collectionHash = $this->getHash(); return $this->collection; @@ -154,7 +154,7 @@ public function getCollection() // Save immediately. // Note additional deferred save can occur in _destruct() - $this->cache->set(self::CACHE_KEY, $this->collection); + $this->cache->set(CachedConfigCollection::CACHE_KEY, $this->collection); $this->collectionHash = $this->getHash(); return $this->collection; } @@ -167,7 +167,7 @@ public function __destruct() // Ensure back-end cache is updated if ($this->collection && $this->collectionHash) { if ($this->getHash() !== $this->collectionHash) { - $this->cache->set(self::CACHE_KEY, $this->collection); + $this->cache->set(CachedConfigCollection::CACHE_KEY, $this->collection); } // Prevent double-destruct diff --git a/src/Collections/DeltaConfigCollection.php b/src/Collections/DeltaConfigCollection.php index 57f1a53..83f8fdb 100644 --- a/src/Collections/DeltaConfigCollection.php +++ b/src/Collections/DeltaConfigCollection.php @@ -141,7 +141,7 @@ public function isDeltaReset($class = null) return isset($deltas[0]['type']) && in_array( $deltas[0]['type'], - [self::REPLACE, self::CLEAR] + [DeltaConfigCollection::REPLACE, DeltaConfigCollection::CLEAR] ); } @@ -172,12 +172,12 @@ public function set(string $class, ?string $name, mixed $data, array $metadata = $this->clearDeltas($class, $name); if ($name) { $this->addDelta($class, [ - 'type' => self::SET, + 'type' => DeltaConfigCollection::SET, 'config' => [$name => $data], ]); } else { $this->addDelta($class, [ - 'type' => self::REPLACE, + 'type' => DeltaConfigCollection::REPLACE, 'config' => $data, ]); } @@ -190,12 +190,12 @@ public function remove(string $class, ?string $name = null): static $this->clearDeltas($class, $name); if ($name) { $this->addDelta($class, [ - 'type' => self::REMOVE, + 'type' => DeltaConfigCollection::REMOVE, 'config' => [$name => true], ]); } else { $this->addDelta($class, [ - 'type' => self::CLEAR, + 'type' => DeltaConfigCollection::CLEAR, ]); } return $this; @@ -210,7 +210,7 @@ public function merge(string $class, string|null $name, array $value): static $config = $value; } $this->addDelta($class, [ - 'type' => self::MERGE, + 'type' => DeltaConfigCollection::MERGE, 'config' => $config, ]); return $this; diff --git a/src/Transformer/YamlTransformer.php b/src/Transformer/YamlTransformer.php index c8812f9..958e63f 100644 --- a/src/Transformer/YamlTransformer.php +++ b/src/Transformer/YamlTransformer.php @@ -333,7 +333,7 @@ protected function calculateDependencies($documents) // Add 'after' dependencies $dependencies = $this->addDependencies( $header, - self::AFTER_FLAG, + YamlTransformer::AFTER_FLAG, $dependencies, $documents ); @@ -341,7 +341,7 @@ protected function calculateDependencies($documents) // Add 'before' dependencies $dependencies = $this->addDependencies( $header, - self::BEFORE_FLAG, + YamlTransformer::BEFORE_FLAG, $dependencies, $documents ); @@ -363,7 +363,7 @@ protected function calculateDependencies($documents) protected function addDependencies($header, $flag, $dependencies, $documents) { // If header isn't set then return dependencies - if (!isset($header[$flag]) || !in_array($flag, [self::BEFORE_FLAG, self::AFTER_FLAG])) { + if (!isset($header[$flag]) || !in_array($flag, [YamlTransformer::BEFORE_FLAG, YamlTransformer::AFTER_FLAG])) { return $dependencies; } @@ -383,7 +383,7 @@ protected function addDependencies($header, $flag, $dependencies, $documents) $dependencies[$dependencyName] = []; } - if ($flag == self::AFTER_FLAG) { + if ($flag == YamlTransformer::AFTER_FLAG) { // For 'after' we add the given dependency to the current document $dependencies[$header['name']][] = $dependencyName; } else { @@ -538,12 +538,12 @@ protected function filterByOnlyAndExcept() $filtered = []; foreach ($documents as $key => $document) { // If not all rules match, then we exclude this document - if (!$this->testRules($document['header'], self::ONLY_FLAG)) { + if (!$this->testRules($document['header'], YamlTransformer::ONLY_FLAG)) { continue; } // If all rules pass, then we exclude this document - if ($this->testRules($document['header'], self::EXCEPT_FLAG)) { + if ($this->testRules($document['header'], YamlTransformer::EXCEPT_FLAG)) { continue; } @@ -566,7 +566,7 @@ protected function testRules($header, $flag) // If flag is not set, then it has no tests if (!isset($header[$flag])) { // We want only to pass, except to fail - return $flag === self::ONLY_FLAG; + return $flag === YamlTransformer::ONLY_FLAG; } if (!is_array($header[$flag])) { @@ -592,7 +592,7 @@ protected function testRules($header, $flag) * @return bool * @throws Exception */ - protected function testSingleRule($rule, $params, $flag = self::ONLY_FLAG) + protected function testSingleRule($rule, $params, $flag = YamlTransformer::ONLY_FLAG) { $rule = strtolower($rule ?? ''); if (!$this->hasRule($rule)) { @@ -637,16 +637,16 @@ protected function evaluateConditions($source, $flag, $condition) } // Only fails if any are false - if ($flag === self::ONLY_FLAG && !$result) { + if ($flag === YamlTransformer::ONLY_FLAG && !$result) { return false; } // Except succeeds if any true - if ($flag === self::EXCEPT_FLAG && $result) { + if ($flag === YamlTransformer::EXCEPT_FLAG && $result) { return true; } } // Default based on flag - return $flag === self::ONLY_FLAG; + return $flag === YamlTransformer::ONLY_FLAG; } }