Skip to content

Commit a4fc28c

Browse files
authored
Add GitHub actions for CI (#4)
* Add GitHub actions for CI * Update files based on CI feedback
1 parent b91be18 commit a4fc28c

14 files changed

Lines changed: 126 additions & 19 deletions

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: jeremeamia

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "composer"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
versioning-strategy: "increase-if-necessary"
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "monthly"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# GitHub Actions Documentation: https://docs.github.com/en/actions
2+
3+
name: "build"
4+
5+
on:
6+
push:
7+
branches:
8+
- "main"
9+
tags:
10+
- "*"
11+
pull_request:
12+
branches:
13+
- "main"
14+
15+
# Cancels all previous workflow runs for the same branch that have not yet completed.
16+
concurrency:
17+
# The concurrency group contains the workflow name and the branch name.
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
env:
22+
COMPOSER_ROOT_VERSION: "1.99.99"
23+
24+
jobs:
25+
coding-standards:
26+
name: "Coding standards"
27+
runs-on: "ubuntu-latest"
28+
steps:
29+
- name: "Checkout repository"
30+
uses: "actions/checkout@v2"
31+
32+
- name: "Install PHP"
33+
uses: "shivammathur/setup-php@v2"
34+
with:
35+
php-version: "8.1"
36+
coverage: none
37+
38+
- name: "Install dependencies (Composer)"
39+
uses: "ramsey/composer-install@v2"
40+
41+
- name: "Check coding standards (PHP CS Fixer)"
42+
shell: "bash"
43+
run: "composer style-lint"
44+
45+
static-analysis:
46+
name: "Static analysis"
47+
runs-on: "ubuntu-latest"
48+
steps:
49+
- name: "Checkout repository"
50+
uses: "actions/checkout@v2"
51+
52+
- name: "Install PHP"
53+
uses: "shivammathur/setup-php@v2"
54+
with:
55+
php-version: "8.1"
56+
coverage: "none"
57+
58+
- name: "Install dependencies (Composer)"
59+
uses: "ramsey/composer-install@v2"
60+
61+
- name: "Statically analyze code (PHPStan)"
62+
shell: "bash"
63+
run: "composer stan"
64+
65+
unit-tests:
66+
name: "Unit tests"
67+
runs-on: "ubuntu-latest"
68+
steps:
69+
- name: "Checkout repository"
70+
uses: "actions/checkout@v2"
71+
72+
- name: "Install PHP"
73+
uses: "shivammathur/setup-php@v2"
74+
with:
75+
php-version: "8.1"
76+
ini-values: "memory_limit=-1"
77+
78+
- name: "Install dependencies (Composer)"
79+
uses: "ramsey/composer-install@v2"
80+
81+
- name: "Run unit tests (PHPUnit)"
82+
shell: "bash"
83+
run: "composer test-ci"

src/Elements/Image.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010
#[RequiresAllOf('image_url', 'alt_text')]
1111
class Image extends Element
1212
{
13+
#[Property('image_url'), ValidString(3000)]
14+
public ?string $imageUrl;
15+
16+
#[Property('alt_text'), ValidString(2000)]
17+
public ?string $altText;
18+
1319
public function __construct(
14-
#[Property('image_url'), ValidString(3000)] public ?string $imageUrl = null,
15-
#[Property('alt_text'), ValidString(2000)] public ?string $altText = null,
20+
?string $imageUrl = null,
21+
?string $altText = null,
1622
) {
1723
parent::__construct();
1824
$this->imageUrl($imageUrl);

src/Hydration/AliasType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#[Attribute(Attribute::TARGET_CLASS)]
1111
class AliasType
1212
{
13-
public function __construct(
14-
public readonly ?Type $type = null,
15-
) {}
13+
public function __construct(public readonly ?Type $type = null)
14+
{
15+
}
1616
}

src/Hydration/Dehydrator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
class Dehydrator
1414
{
15-
public function __construct(
16-
private Component $component
17-
) {}
15+
public function __construct(private Component $component)
16+
{
17+
}
1818

1919
public function getArrayData(): array
2020
{

src/Hydration/Hydrator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public static function forJson(string $json): self
3333
* @param array<string, mixed> $data
3434
*/
3535
public function __construct(private array $data)
36-
{}
36+
{
37+
}
3738

3839
/**
3940
* @param class-string $targetClass
@@ -111,6 +112,7 @@ private function fillComponent(Component $component): void
111112
private function setProperty(ReflectionProperty $reflection, Property $property, Closure $setValue): void
112113
{
113114
$field = $property->field ?? $reflection->getName();
115+
/** @phpstan-ignore-next-line The getName() method seems to work fine, but is not documented. */
114116
$propType = $reflection->getType()->getName();
115117

116118
if (is_a($propType, Component::class, true)) {
@@ -129,7 +131,7 @@ private function setProperty(ReflectionProperty $reflection, Property $property,
129131
private function setFauxProperty(FauxProperty $property, Closure $setValue): void
130132
{
131133
if ($property->fields === ['*']) {
132-
$setValue(array_map(fn(array $value) => Component::fromArray($value), $this->useAllAsArray()));
134+
$setValue(array_map(fn (array $value) => Component::fromArray($value), $this->useAllAsArray()));
133135
} else {
134136
$setValue($this->useValues(...$property->fields));
135137
}

src/Hydration/OmitType.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
#[Attribute(Attribute::TARGET_CLASS)]
1010
class OmitType
1111
{
12-
1312
}

src/Property.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ class Property
1212
public function __construct(
1313
public readonly ?string $field = null,
1414
public readonly bool $spread = false,
15-
) {}
15+
) {
16+
}
1617
}

src/Validation/Context.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Context
1111
public function __construct(
1212
/** @var array<string> */
1313
private array $segments = [],
14-
) {}
14+
) {
15+
}
1516

1617
public function add(Component $component): void
1718
{

0 commit comments

Comments
 (0)