Skip to content

Commit

Permalink
Lint and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatosbc committed Dec 24, 2024
1 parent b842625 commit 6068ebb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .phpcs-cache

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Strategy/AbstractStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class AbstractStrategy implements StrategyInterface
* @var array<string, mixed>
*/
protected array $options = [];

/**
* Configure the strategy with optional parameters
*
Expand All @@ -30,7 +30,7 @@ public function configure(array $options = []): void
{
$this->options = array_merge($this->options, $options);
}

/**
* Default validation implementation that always returns true
* Override this method in concrete strategies to implement specific validation logic
Expand All @@ -42,7 +42,7 @@ public function validate(array $data): bool
{
return true;
}

/**
* Determine if this strategy can handle the given data
*
Expand Down
16 changes: 8 additions & 8 deletions src/Strategy/StrategyContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StrategyContext
* Default strategy to use when no other strategy matches
*/
private ?StrategyInterface $defaultStrategy = null;

/**
* Add a strategy with optional configuration
*
Expand All @@ -42,7 +42,7 @@ public function addStrategy(StrategyInterface $strategy, array $config = []): se
$this->strategies[] = $strategy;
return $this;
}

/**
* Set a default strategy to use when no other strategy matches
*
Expand All @@ -54,7 +54,7 @@ public function setDefaultStrategy(StrategyInterface $strategy): self
$this->defaultStrategy = $strategy;
return $this;
}

/**
* Execute the appropriate strategy for the given data
*
Expand All @@ -65,14 +65,14 @@ public function setDefaultStrategy(StrategyInterface $strategy): self
public function executeStrategy(array $data): mixed
{
$strategy = $this->resolveStrategy($data);

if (!$strategy->validate($data)) {
throw new RuntimeException('Invalid data for strategy execution');
}

return $strategy->execute($data);
}

/**
* Find the first strategy that supports the given data
*
Expand All @@ -87,11 +87,11 @@ private function resolveStrategy(array $data): StrategyInterface
return $strategy;
}
}

if ($this->defaultStrategy !== null) {
return $this->defaultStrategy;
}

throw new RuntimeException('No suitable strategy found for the given data');
}
}
6 changes: 3 additions & 3 deletions src/Traits/ConfigurableStrategyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait ConfigurableStrategyTrait
* @var string[]
*/
protected array $requiredOptions = [];

/**
* Configure the strategy with options
*
Expand All @@ -38,7 +38,7 @@ public function configure(array $options = []): void
$this->validateOptions($options);
$this->options = array_merge($this->options, $options);
}

/**
* Validate that all required options are present
*
Expand All @@ -54,7 +54,7 @@ protected function validateOptions(array $options): void
);
}
}

/**
* Get an option value with a default fallback
*
Expand Down

0 comments on commit 6068ebb

Please sign in to comment.