Skip to content

Commit

Permalink
added correct types to everything
Browse files Browse the repository at this point in the history
  • Loading branch information
matthi4s committed Aug 15, 2022
1 parent 0e4bc48 commit bdb7ff6
Show file tree
Hide file tree
Showing 60 changed files with 308 additions and 391 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
php-version: [ '7.4', '8.0', '8.1' ]
php-version: [ '8.1' ]

name: Run tests on PHP v${{ matrix.php-version }}

Expand Down
7 changes: 2 additions & 5 deletions src/Analyser/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@
*/
abstract class Analyser implements AnalyserInterface
{
/**
* @var AnalysableLogInterface
*/
protected $log;
protected ?AnalysableLogInterface $log = null;

/**
* Set the log
*
* @param AnalysableLogInterface $log
* @return $this
*/
public function setLog(AnalysableLogInterface $log)
public function setLog(AnalysableLogInterface $log): static
{
$this->log = $log;
return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Analyser/AnalyserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ interface AnalyserInterface
* @param AnalysableLogInterface $log
* @return $this
*/
public function setLog(AnalysableLogInterface $log);
public function setLog(AnalysableLogInterface $log): static;

/**
* Analyse a log and return an Analysis
*
* @return AnalysisInterface
*/
public function analyse();
public function analyse(): AnalysisInterface;
}
38 changes: 19 additions & 19 deletions src/Analyser/PatternAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
class PatternAnalyser extends Analyser
{
/**
* @var array
* @var class-string<PatternInsightInterface>[]
*/
protected $possibleInsightClasses = [];
protected array $possibleInsightClasses = [];

/**
* Set possible insight classes
*
* Every class must implement PatternInsightInterface
*
* @param array $insightClasses
* @param class-string<PatternInsightInterface>[] $insightClasses
* @return $this
*/
public function setPossibleInsightClasses(array $insightClasses)
public function setPossibleInsightClasses(array $insightClasses): static
{
$this->possibleInsightClasses = [];
foreach ($insightClasses as $insightClass) {
Expand All @@ -42,10 +42,10 @@ public function setPossibleInsightClasses(array $insightClasses)
*
* The class must implement PatternInsightInterface
*
* @param string $insightClass
* @param class-string<PatternInsightInterface> $insightClass
* @return $this
*/
public function addPossibleInsightClass(string $insightClass)
public function addPossibleInsightClass(string $insightClass): static
{
if (!is_subclass_of($insightClass, PatternInsightInterface::class)) {
throw new \InvalidArgumentException("Class " . $insightClass . " does not implement " . PatternInsightInterface::class . ".");
Expand All @@ -58,10 +58,10 @@ public function addPossibleInsightClass(string $insightClass)
/**
* Find a possible insight class
*
* @param string $insightClass
* @return int|string
* @param class-string<PatternInsightInterface> $insightClass
* @return int
*/
protected function findPossibleInsightClass(string $insightClass)
protected function findPossibleInsightClass(string $insightClass): int
{
$index = array_search($insightClass, $this->possibleInsightClasses);
if ($index === false) {
Expand All @@ -73,9 +73,9 @@ protected function findPossibleInsightClass(string $insightClass)
/**
* Remove a possible insight class
*
* @param string $insightClass
* @param class-string<PatternInsightInterface> $insightClass
*/
public function removePossibleInsightClass(string $insightClass)
public function removePossibleInsightClass(string $insightClass): void
{
$index = $this->findPossibleInsightClass($insightClass);
unset($this->possibleInsightClasses[$index]);
Expand All @@ -86,10 +86,10 @@ public function removePossibleInsightClass(string $insightClass)
*
* The $childInsightClass has to extend $parentInsightClass
*
* @param string $parentInsightClass
* @param string $childInsightClass
* @param class-string<PatternInsightInterface> $parentInsightClass
* @param class-string<PatternInsightInterface> $childInsightClass
*/
public function overridePossibleInsightClass(string $parentInsightClass, string $childInsightClass)
public function overridePossibleInsightClass(string $parentInsightClass, string $childInsightClass): void
{
if (!is_subclass_of($childInsightClass, $parentInsightClass)) {
throw new \InvalidArgumentException("Class " . $childInsightClass . " does not extend " . $parentInsightClass . ".");
Expand All @@ -104,7 +104,7 @@ public function overridePossibleInsightClass(string $parentInsightClass, string
*
* @return AnalysisInterface
*/
public function analyse()
public function analyse(): AnalysisInterface
{
$analysis = new Analysis();

Expand All @@ -131,15 +131,15 @@ public function analyse()
*
* @param EntryInterface $entry
* @param string $possibleInsightClass
* @param $patternKey
* @param mixed $patternKey
* @param string $pattern
* @return bool|PatternInsightInterface[]
* @return null|PatternInsightInterface[]
*/
protected function analyseEntry(EntryInterface $entry, string $possibleInsightClass, $patternKey, string $pattern)
protected function analyseEntry(EntryInterface $entry, string $possibleInsightClass, mixed $patternKey, string $pattern): ?array
{
$result = preg_match_all($pattern, $entry, $matches, PREG_SET_ORDER);
if ($result === false || $result === 0) {
return false;
return null;
}

$return = [];
Expand Down
36 changes: 16 additions & 20 deletions src/Analysis/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ class Analysis implements AnalysisInterface
/**
* @var InsightInterface[]
*/
protected $insights = [];

/**
* @var int
*/
protected $iterator = 0;
protected array $insights = [];
protected int $iterator = 0;

/**
* Set all insights at once in an array replacing the current insights
*
* @param InsightInterface[] $insights
* @return $this
*/
public function setInsights(array $insights = [])
public function setInsights(array $insights = []): static
{
$this->insights = $insights;
return $this;
Expand All @@ -38,7 +34,7 @@ public function setInsights(array $insights = [])
* @param InsightInterface $insight
* @return $this
*/
public function addInsight(InsightInterface $insight)
public function addInsight(InsightInterface $insight): static
{
foreach ($this as $existingInsight) {
if (get_class($insight) === get_class($existingInsight) && $existingInsight->isEqual($insight)) {
Expand All @@ -54,7 +50,7 @@ public function addInsight(InsightInterface $insight)
/**
* Get all insights
*
* @return array
* @return InsightInterface[]
*/
public function getInsights(): array
{
Expand All @@ -64,10 +60,10 @@ public function getInsights(): array
/**
* Get all insights that are extended from $extendedFrom (class name)
*
* @param string $extendedFrom
* @return array
* @param class-string<InsightInterface> $extendedFrom
* @return InsightInterface[]
*/
public function getFilteredInsights($extendedFrom)
public function getFilteredInsights(string $extendedFrom): array
{
$returnInsights = [];
foreach ($this->getInsights() as $insight) {
Expand All @@ -82,7 +78,7 @@ public function getFilteredInsights($extendedFrom)
/**
* Get all problem insights
*
* @return array
* @return ProblemInterface[]
*/
public function getProblems(): array
{
Expand All @@ -92,7 +88,7 @@ public function getProblems(): array
/**
* Get all information insights
*
* @return array
* @return InformationInterface[]
*/
public function getInformation(): array
{
Expand Down Expand Up @@ -165,7 +161,7 @@ public function count(): int
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset): bool
public function offsetExists(mixed $offset): bool
{
return isset($this->insights[$offset]);
}
Expand All @@ -176,28 +172,28 @@ public function offsetExists($offset): bool
* @param mixed $offset
* @return InsightInterface
*/
public function offsetGet($offset): InsightInterface
public function offsetGet(mixed $offset): InsightInterface
{
return $this->insights[$offset];
}

/**
* Offset to set
*
* @param $offset
* @param mixed $offset
* @param InsightInterface $value
*/
public function offsetSet($offset, $value): void
public function offsetSet(mixed $offset, mixed $value): void
{
$this->insights[$offset] = $value;
}

/**
* Offset to unset
*
* @param $offset
* @param mixed $offset
*/
public function offsetUnset($offset): void
public function offsetUnset(mixed $offset): void
{
unset($this->insights[$offset]);
}
Expand Down
22 changes: 18 additions & 4 deletions src/Analysis/AnalysisInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,37 @@ interface AnalysisInterface extends \Iterator, \Countable, \ArrayAccess
/**
* Set all insights at once in an array replacing the current insights
*
* @param array $insights
* @param InsightInterface[] $insights
* @return $this
*/
public function setInsights(array $insights = []);
public function setInsights(array $insights = []): static;

/**
* Add an insight
*
* @param InsightInterface $insight
* @return $this
*/
public function addInsight(InsightInterface $insight);
public function addInsight(InsightInterface $insight): static;

/**
* Get all insights
*
* @return array
* @return InsightInterface[]
*/
public function getInsights(): array;

/**
* Get all problem insights
*
* @return ProblemInterface[]
*/
public function getProblems(): array;

/**
* Get all information insights
*
* @return InformationInterface[]
*/
public function getInformation(): array;
}
25 changes: 9 additions & 16 deletions src/Analysis/Information.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@
*/
abstract class Information extends Insight implements InformationInterface
{
/**
* @var string
*/
protected $label;

/**
* @var
*/
protected $value;
protected ?string $label = null;
protected mixed $value = null;

/**
* Get the information label
Expand All @@ -33,9 +26,9 @@ public function getLabel(): string
* Set the information label
*
* @param string $label
* @return Information
* @return $this
*/
protected function setLabel(string $label)
protected function setLabel(string $label): static
{
$this->label = $label;
return $this;
Expand All @@ -46,7 +39,7 @@ protected function setLabel(string $label)
*
* @return mixed
*/
public function getValue()
public function getValue(): mixed
{
return $this->value;
}
Expand All @@ -57,14 +50,14 @@ public function getValue()
* @param mixed $value
* @return $this
*/
public function setValue($value)
public function setValue(mixed $value): static
{
$this->value = $value;
return $this;
}

/**
* Get a human readable message
* Get a human-readable message
*
* @return string
*/
Expand All @@ -76,10 +69,10 @@ public function getMessage(): string
/**
* Check if the $insight object is equal with the current object
*
* @param static $insight
* @param InsightInterface $insight
* @return bool
*/
public function isEqual($insight): bool
public function isEqual(InsightInterface $insight): bool
{
return $this->getLabel() === $insight->getLabel() && $this->getValue() === $insight->getValue();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/InformationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public function getLabel(): string;
* @param mixed $value
* @return $this
*/
public function setValue($value);
public function setValue(mixed $value): static;

/**
* Get the information value
*
* @return mixed
*/
public function getValue();
public function getValue(): mixed;
}
Loading

0 comments on commit bdb7ff6

Please sign in to comment.