diff --git a/Makefile b/Makefile index a8da0fd7..a2fb6ce8 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SHELL := bash PATH := $(PATH):$(CURDIR)/vendor/bin .PHONY: test -test: test-validate-composer test-code-style test-psalm test-phpunit test-examples test-composer-normalize +test: test-validate-composer test-code-style test-psalm test-phpunit test-examples test-composer-normalize test-phpmd .PHONY: test-code-style test-code-style: dependencies @@ -33,6 +33,11 @@ test-composer-normalize: dependencies test-composer-normalize: composer normalize --dry-run --diff +.PHONY: test-phpmd +test-phpmd: dependencies +test-phpmd: + phpmd ./src text rulesets.xml + .PHONY: test-prettier test-prettier: yarn diff --git a/composer.json b/composer.json index c71873c7..c0545cb9 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "require-dev": { "ergebnis/composer-normalize": "^2.2", "friendsofphp/php-cs-fixer": "^2.16", + "phpmd/phpmd": "^2.9", "phpunit/phpunit": "^8", "vimeo/psalm": "^3.7" }, diff --git a/rulesets.xml b/rulesets.xml new file mode 100644 index 00000000..3e4c5a90 --- /dev/null +++ b/rulesets.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/src/Domain/ValueObject/Date.php b/src/Domain/ValueObject/Date.php index dddc36e0..0ef71de2 100644 --- a/src/Domain/ValueObject/Date.php +++ b/src/Domain/ValueObject/Date.php @@ -15,6 +15,7 @@ use DateTimeImmutable as PhpDateTimeImmutable; use DateTimeInterface as PhpDateTimeInterface; use InvalidArgumentException; +use RuntimeException; final class Date extends PointInTime { @@ -26,7 +27,7 @@ public static function fromDateTimeInterface(PhpDateTimeInterface $dateTime): se ); if ($dateTime === false) { - throw new \RuntimeException('Unexpected date time value.'); + throw new RuntimeException('Unexpected date time value.'); } return new self($dateTime); diff --git a/src/Domain/ValueObject/GeographicPosition.php b/src/Domain/ValueObject/GeographicPosition.php index ce4981de..6d2aae3b 100644 --- a/src/Domain/ValueObject/GeographicPosition.php +++ b/src/Domain/ValueObject/GeographicPosition.php @@ -11,6 +11,8 @@ namespace Eluceo\iCal\Domain\ValueObject; +use InvalidArgumentException; + final class GeographicPosition { private float $latitude; @@ -22,11 +24,11 @@ private function __construct(float $latitude, float $longitude) $this->longitude = $longitude; if ($this->latitude < -90 || $this->latitude > 90) { - throw new \InvalidArgumentException("The geographical latitude must be a value between -90 and 90 degrees. '{$this->latitude}' was given."); + throw new InvalidArgumentException("The geographical latitude must be a value between -90 and 90 degrees. '{$this->latitude}' was given."); } if ($this->longitude < -180 || $this->longitude > 180) { - throw new \InvalidArgumentException("The geographical longitude must be a value between -180 and 180 degrees. '{$this->longitude}' was given."); + throw new InvalidArgumentException("The geographical longitude must be a value between -180 and 180 degrees. '{$this->longitude}' was given."); } } diff --git a/src/Domain/ValueObject/Timestamp.php b/src/Domain/ValueObject/Timestamp.php index 18298c98..4ddd856a 100644 --- a/src/Domain/ValueObject/Timestamp.php +++ b/src/Domain/ValueObject/Timestamp.php @@ -13,6 +13,7 @@ use DateTimeImmutable as PhpDateTimeImmutable; use DateTimeInterface as PhpDateTimeInterface; +use RuntimeException; class Timestamp extends PointInTime { @@ -24,7 +25,7 @@ public static function fromDateTimeInterface(PhpDateTimeInterface $dateTime): se ); if ($dateTime === false) { - throw new \RuntimeException('Unexpected date time value.'); + throw new RuntimeException('Unexpected date time value.'); } return new static($dateTime); diff --git a/src/Presentation/Component.php b/src/Presentation/Component.php index b8697fc5..2b792d0c 100644 --- a/src/Presentation/Component.php +++ b/src/Presentation/Component.php @@ -29,7 +29,9 @@ class Component implements IteratorAggregate public function __construct(string $componentName, array $properties = []) { $this->componentName = strtoupper($componentName); - array_walk($properties, [$this, 'addProperty']); + foreach ($properties as $property) { + $this->addProperty($property); + } } public function withProperty(Property $property): self diff --git a/src/Presentation/Component/Property.php b/src/Presentation/Component/Property.php index 3b7d3981..167b4031 100644 --- a/src/Presentation/Component/Property.php +++ b/src/Presentation/Component/Property.php @@ -32,7 +32,9 @@ public function __construct(string $name, Value $value, array $parameters = []) { $this->name = strtoupper($name); $this->value = $value; - array_walk($parameters, [$this, 'addParameter']); + foreach ($parameters as $parameter) { + $this->addParameter($parameter); + } } public function __toString(): string diff --git a/src/Presentation/Component/Property/Value/DateTimeValue.php b/src/Presentation/Component/Property/Value/DateTimeValue.php index cd832345..de4ab09d 100644 --- a/src/Presentation/Component/Property/Value/DateTimeValue.php +++ b/src/Presentation/Component/Property/Value/DateTimeValue.php @@ -11,6 +11,8 @@ namespace Eluceo\iCal\Presentation\Component\Property\Value; +use BadMethodCallException; +use DateTimeZone; use Eluceo\iCal\Domain\ValueObject\DateTime; use Eluceo\iCal\Domain\ValueObject\Timestamp; use Eluceo\iCal\Presentation\Component\Property\Value; @@ -28,7 +30,7 @@ private function __construct(string $valueAsString) public static function fromTimestamp(Timestamp $timestamp): self { - $dateTime = $timestamp->getDateTime()->setTimezone(new \DateTimeZone('UTC')); + $dateTime = $timestamp->getDateTime()->setTimezone(new DateTimeZone('UTC')); return new self($dateTime->format(self::FORMAT_UTC_DATE_TIME)); } @@ -38,7 +40,7 @@ public static function fromDateTime(DateTime $dateTime): self $format = self::FORMAT_NO_TIMEZONE; if ($dateTime->hasDateTimeZone()) { - throw new \BadMethodCallException('not implemented yet'); + throw new BadMethodCallException('not implemented yet'); } return new static($dateTime->getDateTime()->format($format)); diff --git a/src/Presentation/Component/Property/Value/ListValue.php b/src/Presentation/Component/Property/Value/ListValue.php index be2aba59..c9d02d32 100644 --- a/src/Presentation/Component/Property/Value/ListValue.php +++ b/src/Presentation/Component/Property/Value/ListValue.php @@ -25,7 +25,9 @@ final class ListValue extends Value */ public function __construct(array $values) { - array_walk($values, [$this, 'addValue']); + foreach ($values as $value) { + $this->addValue($value); + } } public function __toString(): string diff --git a/src/Presentation/Factory/EventFactory.php b/src/Presentation/Factory/EventFactory.php index 308f443f..13c5f165 100644 --- a/src/Presentation/Factory/EventFactory.php +++ b/src/Presentation/Factory/EventFactory.php @@ -26,6 +26,9 @@ use Eluceo\iCal\Presentation\Component\Property\Value\TextValue; use Generator; +/** + * @SuppressWarnings("CouplingBetweenObjects") + */ class EventFactory { /**