Skip to content

Commit

Permalink
Add GitHub actions for CI (#4)
Browse files Browse the repository at this point in the history
* Add GitHub actions for CI
* Update files based on CI feedback
  • Loading branch information
jeremeamia authored Feb 9, 2022
1 parent b91be18 commit a4fc28c
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: jeremeamia
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "monthly"
versioning-strategy: "increase-if-necessary"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
83 changes: 83 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# GitHub Actions Documentation: https://docs.github.com/en/actions

name: "build"

on:
push:
branches:
- "main"
tags:
- "*"
pull_request:
branches:
- "main"

# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
COMPOSER_ROOT_VERSION: "1.99.99"

jobs:
coding-standards:
name: "Coding standards"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
coverage: none

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@v2"

- name: "Check coding standards (PHP CS Fixer)"
shell: "bash"
run: "composer style-lint"

static-analysis:
name: "Static analysis"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
coverage: "none"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@v2"

- name: "Statically analyze code (PHPStan)"
shell: "bash"
run: "composer stan"

unit-tests:
name: "Unit tests"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
ini-values: "memory_limit=-1"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@v2"

- name: "Run unit tests (PHPUnit)"
shell: "bash"
run: "composer test-ci"
10 changes: 8 additions & 2 deletions src/Elements/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
#[RequiresAllOf('image_url', 'alt_text')]
class Image extends Element
{
#[Property('image_url'), ValidString(3000)]
public ?string $imageUrl;

#[Property('alt_text'), ValidString(2000)]
public ?string $altText;

public function __construct(
#[Property('image_url'), ValidString(3000)] public ?string $imageUrl = null,
#[Property('alt_text'), ValidString(2000)] public ?string $altText = null,
?string $imageUrl = null,
?string $altText = null,
) {
parent::__construct();
$this->imageUrl($imageUrl);
Expand Down
6 changes: 3 additions & 3 deletions src/Hydration/AliasType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#[Attribute(Attribute::TARGET_CLASS)]
class AliasType
{
public function __construct(
public readonly ?Type $type = null,
) {}
public function __construct(public readonly ?Type $type = null)
{
}
}
6 changes: 3 additions & 3 deletions src/Hydration/Dehydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

class Dehydrator
{
public function __construct(
private Component $component
) {}
public function __construct(private Component $component)
{
}

public function getArrayData(): array
{
Expand Down
6 changes: 4 additions & 2 deletions src/Hydration/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static function forJson(string $json): self
* @param array<string, mixed> $data
*/
public function __construct(private array $data)
{}
{
}

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

if (is_a($propType, Component::class, true)) {
Expand All @@ -129,7 +131,7 @@ private function setProperty(ReflectionProperty $reflection, Property $property,
private function setFauxProperty(FauxProperty $property, Closure $setValue): void
{
if ($property->fields === ['*']) {
$setValue(array_map(fn(array $value) => Component::fromArray($value), $this->useAllAsArray()));
$setValue(array_map(fn (array $value) => Component::fromArray($value), $this->useAllAsArray()));
} else {
$setValue($this->useValues(...$property->fields));
}
Expand Down
1 change: 0 additions & 1 deletion src/Hydration/OmitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@
#[Attribute(Attribute::TARGET_CLASS)]
class OmitType
{

}
3 changes: 2 additions & 1 deletion src/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ class Property
public function __construct(
public readonly ?string $field = null,
public readonly bool $spread = false,
) {}
) {
}
}
3 changes: 2 additions & 1 deletion src/Validation/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Context
public function __construct(
/** @var array<string> */
private array $segments = [],
) {}
) {
}

public function add(Component $component): void
{
Expand Down
3 changes: 2 additions & 1 deletion src/Validation/ValidCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ValidCollection implements PropertyRule
public function __construct(
private int $maxCount = 0,
private int $minCount = 1,
) {}
) {
}

public function check(Component $component, string $field, mixed $value): void
{
Expand Down
3 changes: 2 additions & 1 deletion src/Validation/ValidDatetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class ValidDatetime implements PropertyRule
public function __construct(
private string $phpFormat,
private string $humanFormat,
) {}
) {
}

public function check(Component $component, string $field, mixed $value): void
{
Expand Down
3 changes: 2 additions & 1 deletion src/Validation/ValidInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ValidInt implements PropertyRule
public function __construct(
private int $max = 0,
private int $min = 1,
) {}
) {
}

public function check(Component $component, string $field, mixed $value): void
{
Expand Down
6 changes: 3 additions & 3 deletions src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Validator
{
private ?Closure $preValidation = null;

public function __construct(
private Component $component,
) {}
public function __construct(private Component $component)
{
}

public function addPreValidation(callable $preValidation): void
{
Expand Down

0 comments on commit a4fc28c

Please sign in to comment.