Skip to content

Commit

Permalink
Merge pull request #1 from einar-hansen/feature/code-styling
Browse files Browse the repository at this point in the history
Update codestyle
  • Loading branch information
einar-hansen authored Jul 18, 2024
2 parents b50476b + 038394f commit d87fd57
Show file tree
Hide file tree
Showing 41 changed files with 383 additions and 513 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10.0",
"symfony/http-client": "^6.1",
"symfony/var-dumper": "^6.1"
},
Expand All @@ -50,7 +50,7 @@
"scripts": {
"analyse": "vendor/bin/phpstan --level=9 analyse",
"format": "vendor/bin/pint",
"test": "vendor/bin/pest",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
},
"config": {
Expand Down
12 changes: 6 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
5 changes: 2 additions & 3 deletions src/Data/Area.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public function __construct(
public readonly ?int $parentId = null,
public readonly ?string $parentName = null,
public readonly array $children = [],
) {
}
) {}

/**
* {@inheritDoc}
Expand All @@ -36,7 +35,7 @@ public function toArray(): array
'parentName' => $this->parentName,
'children' => array_map(
array: $this->children,
callback: fn (Area $child) => $child->toArray()
callback: fn (Area $area): array => $area->toArray()
),
];
}
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Competition.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public function __construct(
public readonly ?int $seasonCount = null,
public readonly ?Season $season = null,
public readonly ?DateTimeInterface $updatedAt = null,
) {
}
) {}

/**
* {@inheritDoc}
Expand All @@ -36,7 +35,7 @@ public function toArray(): array
'area' => $this->area?->toArray(),
'seasonCount' => $this->seasonCount,
'season' => $this->season?->toArray(),
'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ISO8601),
'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ATOM),
];
}

Expand Down
7 changes: 3 additions & 4 deletions src/Data/Contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ class Contract implements Data
public function __construct(
public readonly ?DateTimeInterface $start = null,
public readonly ?DateTimeInterface $end = null,
) {
}
) {}

/**
* {@inheritDoc}
*/
public function toArray(): array
{
return [
'start' => $this->start?->format(format: DateTimeInterface::ISO8601),
'end' => $this->end?->format(format: DateTimeInterface::ISO8601),
'start' => $this->start?->format(format: DateTimeInterface::ATOM),
'end' => $this->end?->format(format: DateTimeInterface::ATOM),
];
}

Expand Down
11 changes: 5 additions & 6 deletions src/Data/FootballMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class FootballMatch implements Data
{
/**
* @param \EinarHansen\FootballData\Data\Person[] $referees
* @param Person[] $referees
*/
public function __construct(
public readonly int $id,
Expand All @@ -27,8 +27,7 @@ public function __construct(
public readonly DateTimeInterface $updatedAt,
public readonly ?string $group = null,
public readonly array $referees = [],
) {
}
) {}

/**
* {@inheritDoc}
Expand All @@ -42,14 +41,14 @@ public function toArray(): array
'awayTeam' => $this->awayTeam->toArray(),
'score' => $this->score->toArray(),
'matchday' => $this->matchday,
'startingAt' => $this->startingAt->format(format: DateTimeInterface::ISO8601),
'startingAt' => $this->startingAt->format(format: DateTimeInterface::ATOM),
'status' => $this->status->value,
'stage' => $this->stage->value,
'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ISO8601),
'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ATOM),
'group' => $this->group,
'referees' => array_map(
array: $this->referees,
callback: fn (Person $person) => $person->toArray()
callback: fn (Person $person): array => $person->toArray()
),
];
}
Expand Down
11 changes: 5 additions & 6 deletions src/Data/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Person implements Data
{
/**
* @param \EinarHansen\FootballData\Data\Competition[] $competitions
* @param Competition[] $competitions
*/
public function __construct(
public readonly int $id,
Expand All @@ -25,8 +25,7 @@ public function __construct(
public readonly ?Team $team = null,
public readonly ?Contract $contract = null,
public readonly array $competitions = [],
) {
}
) {}

/**
* {@inheritDoc}
Expand All @@ -38,17 +37,17 @@ public function toArray(): array
'name' => $this->name,
'firstName' => $this->firstName,
'lastName' => $this->lastName,
'dateOfBirth' => $this->dateOfBirth->format(format: DateTimeInterface::ISO8601),
'dateOfBirth' => $this->dateOfBirth->format(format: DateTimeInterface::ATOM),
'nationality' => $this->nationality,
'position' => $this->position,
'shirtNumber' => $this->shirtNumber,
'team' => $this->team?->toArray(),
'contract' => $this->contract?->toArray(),
'competitions' => array_map(
array: $this->competitions,
callback: fn (Competition $competition) => $competition->toArray()
callback: fn (Competition $competition): array => $competition->toArray()
),
'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ISO8601),
'updatedAt' => $this->updatedAt->format(format: DateTimeInterface::ATOM),
];
}

Expand Down
3 changes: 1 addition & 2 deletions src/Data/PersonGoalScore.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public function __construct(
public readonly int $goals = 0,
public readonly int $assists = 0,
public readonly int $penalties = 0,
) {
}
) {}

/**
* {@inheritDoc}
Expand Down
3 changes: 1 addition & 2 deletions src/Data/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public function __construct(
public readonly ScoreResult $fullTime,
public readonly ScoreResult $halfTime,
public readonly ?string $winner = null,
) {
}
) {}

/**
* {@inheritDoc}
Expand Down
3 changes: 1 addition & 2 deletions src/Data/ScoreResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class ScoreResult implements Data
public function __construct(
public readonly ?int $home = null,
public readonly ?int $away = null,
) {
}
) {}

/**
* {@inheritDoc}
Expand Down
11 changes: 5 additions & 6 deletions src/Data/Season.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public function __construct(
public readonly DateTimeInterface $startingAt,
public readonly DateTimeInterface $endingAt,
public readonly int $matchDay = 0,
public readonly ?Team $winner = null,
) {
}
public readonly ?Team $team = null,
) {}

/**
* {@inheritDoc}
Expand All @@ -25,10 +24,10 @@ public function toArray(): array
{
return [
'id' => $this->id,
'startingAt' => $this->startingAt->format(format: DateTimeInterface::ISO8601),
'endingAt' => $this->endingAt->format(format: DateTimeInterface::ISO8601),
'startingAt' => $this->startingAt->format(format: DateTimeInterface::ATOM),
'endingAt' => $this->endingAt->format(format: DateTimeInterface::ATOM),
'matchDay' => $this->matchDay,
'winner' => $this->winner?->toArray(),
'winner' => $this->team?->toArray(),
];
}

Expand Down
7 changes: 3 additions & 4 deletions src/Data/Standing.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
class Standing implements Data
{
/**
* @param \EinarHansen\FootballData\Data\TablePosition[] $positions
* @param TablePosition[] $positions
*/
public function __construct(
public readonly Stage $stage,
public readonly string $type,
public readonly ?string $group = null,
public readonly array $positions = [],
) {
}
) {}

/**
* {@inheritDoc}
Expand All @@ -31,7 +30,7 @@ public function toArray(): array
'group' => $this->group,
'positions' => array_map(
array: $this->positions,
callback: fn (TablePosition $tablePosition) => $tablePosition->toArray()
callback: fn (TablePosition $tablePosition): array => $tablePosition->toArray()
),
];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Data/TablePosition.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public function __construct(
public readonly int $goalsFor,
public readonly int $goalsAgainst,
public readonly int $goalDifference,
) {
}
) {}

/**
* {@inheritDoc}
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public function __construct(
public readonly ?string $colors = null,
public readonly ?string $venue = null,
public readonly ?DateTimeInterface $updatedAt = null,
) {
}
) {}

/**
* {@inheritDoc}
Expand All @@ -40,7 +39,7 @@ public function toArray(): array
'founded' => $this->founded,
'colors' => $this->colors,
'venue' => $this->venue,
'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ISO8601),
'updatedAt' => $this->updatedAt?->format(format: DateTimeInterface::ATOM),
];
}

Expand Down
4 changes: 1 addition & 3 deletions src/Exceptions/FootballDataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Exception;

class FootballDataException extends Exception
{
}
class FootballDataException extends Exception {}
12 changes: 6 additions & 6 deletions src/Factories/AreaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function make(array $attributes): Area
$attributes = new AttributeBag($attributes);

return new Area(
id: $attributes->integer(key: 'id'),
name: $attributes->string(key: 'name'),
code: $attributes->stringOrNull(key: 'countryCode') ?? $attributes->string(key: 'code'),
image: $attributes->stringOrNull(key: 'flag'),
parentId: $attributes->integerOrNull(key: 'parentAreaId'),
id: $attributes->integer(key: 'id'),
name: $attributes->string(key: 'name'),
code: $attributes->stringOrNull(key: 'countryCode') ?? $attributes->string(key: 'code'),
image: $attributes->stringOrNull(key: 'flag'),
parentId: $attributes->integerOrNull(key: 'parentAreaId'),
parentName: $attributes->stringOrNull(key: 'parentArea'),
children: $attributes->map(
children: $attributes->map(
key: 'childAreas',
callback: fn (array $child): Area => $this->make($child)
)
Expand Down
32 changes: 11 additions & 21 deletions src/Factories/CompetitionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@

class CompetitionFactory implements DataFactory
{
protected readonly AreaFactory $areaFactory;

protected readonly SeasonFactory $seasonFactory;

public function __construct(
?AreaFactory $areaFactory = null,
?SeasonFactory $seasonFactory = null,
) {
$this->areaFactory = $areaFactory ?? new AreaFactory();
$this->seasonFactory = $seasonFactory ?? new SeasonFactory();
}
public function __construct(protected readonly AreaFactory $areaFactory = new AreaFactory(), protected readonly SeasonFactory $seasonFactory = new SeasonFactory()) {}

public function make(array $attributes): Competition
{
Expand All @@ -30,21 +20,21 @@ public function make(array $attributes): Competition
$season = $attributes->arrayOrNull(key: 'currentSeason') ?? $attributes->arrayOrNull(key: 'season');

return new Competition(
id: $attributes->integer(key: 'id'),
name: $attributes->string(key: 'name'),
code: $attributes->string(key: 'code'),
type: $attributes->string(key: 'type'),
image: $attributes->stringOrNull(key: 'emblem'),
area: $this->areaFactory->make(
id: $attributes->integer(key: 'id'),
name: $attributes->string(key: 'name'),
code: $attributes->string(key: 'code'),
type: $attributes->string(key: 'type'),
image: $attributes->stringOrNull(key: 'emblem'),
area: $this->areaFactory->make(
attributes: $attributes->array(key: 'area')
),
seasonCount: $attributes->integer(key: 'numberOfAvailableSeasons'),
season: $season ? $this->seasonFactory->make(
seasonCount: $attributes->integer(key: 'numberOfAvailableSeasons'),
season: $season ? $this->seasonFactory->make(
attributes: $season,
) : null,
updatedAt: $attributes->dateTime(
updatedAt: $attributes->dateTime(
key: 'lastUpdated',
format: DateTimeInterface::ISO8601
format: DateTimeInterface::ATOM
),
);
}
Expand Down
Loading

0 comments on commit d87fd57

Please sign in to comment.