Skip to content

Commit

Permalink
Add PHPMD (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuspoerschke authored Sep 27, 2020
1 parent 017b668 commit 7da2e4b
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
14 changes: 14 additions & 0 deletions rulesets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset name="My first PHPMD rule set"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess"/>
</rule>
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
</ruleset>
3 changes: 2 additions & 1 deletion src/Domain/ValueObject/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use DateTimeImmutable as PhpDateTimeImmutable;
use DateTimeInterface as PhpDateTimeInterface;
use InvalidArgumentException;
use RuntimeException;

final class Date extends PointInTime
{
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/Domain/ValueObject/GeographicPosition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Eluceo\iCal\Domain\ValueObject;

use InvalidArgumentException;

final class GeographicPosition
{
private float $latitude;
Expand All @@ -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.");
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Domain/ValueObject/Timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use DateTimeImmutable as PhpDateTimeImmutable;
use DateTimeInterface as PhpDateTimeInterface;
use RuntimeException;

class Timestamp extends PointInTime
{
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/Presentation/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/Presentation/Component/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/Presentation/Component/Property/Value/DateTimeValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand All @@ -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));
Expand Down
4 changes: 3 additions & 1 deletion src/Presentation/Component/Property/Value/ListValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Presentation/Factory/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
use Eluceo\iCal\Presentation\Component\Property\Value\TextValue;
use Generator;

/**
* @SuppressWarnings("CouplingBetweenObjects")
*/
class EventFactory
{
/**
Expand Down

0 comments on commit 7da2e4b

Please sign in to comment.