Skip to content

Commit

Permalink
ENH Use class name instead of self
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 5, 2024
1 parent 643df8f commit 6563cb0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Collections/CachedConfigCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Collections/DeltaConfigCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}

Expand Down Expand Up @@ -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,
]);
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions src/Transformer/YamlTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,15 @@ protected function calculateDependencies($documents)
// Add 'after' dependencies
$dependencies = $this->addDependencies(
$header,
self::AFTER_FLAG,
YamlTransformer::AFTER_FLAG,
$dependencies,
$documents
);

// Add 'before' dependencies
$dependencies = $this->addDependencies(
$header,
self::BEFORE_FLAG,
YamlTransformer::BEFORE_FLAG,
$dependencies,
$documents
);
Expand All @@ -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;
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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])) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 6563cb0

Please sign in to comment.