diff --git a/app/Models/Constraints/FormatConstraint.php b/app/Models/Constraints/FormatConstraint.php index bfa492b..4f01e53 100644 --- a/app/Models/Constraints/FormatConstraint.php +++ b/app/Models/Constraints/FormatConstraint.php @@ -1,41 +1,41 @@ getConstraintDataByCode('format'); if ($statements->count() !== 0) { /** @var Collection $qualifiers */ $qualifiers = $statements->first()->getQualifiers(); if ($qualifiers->count() !== 0) { $this->regexp = $qualifiers->first()->getValue()->toString(); } } } public function isSatisfiedBy(StatementInterface $statement): bool { $this->init($statement->getProperty()); $value = $statement->getSnak()->getValue()->toString(); $result = (bool)preg_match('/^' . $this->regexp . '$/', $value); - if ($result == false) { + if ($result === false) { $this->addViolation([ 'value' => $value, 'regex' => $this->regexp, ]); } return $result; } } diff --git a/app/Services/ConstraintService.php b/app/Services/ConstraintService.php index eb6a8de..53b824e 100644 --- a/app/Services/ConstraintService.php +++ b/app/Services/ConstraintService.php @@ -1,50 +1,50 @@ $constraintId) { - $constraintClass = 'App\\Models\\Constraints\\' . camel_case($constraintCode) . 'Constraint'; + $constraintClass = 'App\\Models\\Constraints\\' . studly_case($constraintCode) . 'Constraint'; $this->constraints[$constraintId] = $constraintClass; } } public function getConstraintById(string $constraintId): ?ConstraintInterface { if (!\in_array($constraintId, $this->constraints)) { return null; } return new $this->constraints[$constraintId]; } public function getStatementViolations(StatementInterface $statement): ?Collection { $property = $statement->getProperty(); foreach ($this->constraints as $constraintId => $constraintClass) { if (!$property->hasConstraintId($constraintId)) { continue; } /** @var ConstraintInterface $constraint */ $constraint = new $constraintClass(); if (!$constraint->isSatisfiedBy($statement)) { return $constraint->getViolations(); } } return null; } }