Skip to content

Commit

Permalink
Merge pull request #15 from ARCANEDEV/update-cs-fixer
Browse files Browse the repository at this point in the history
Adding CS Fixer with pint
  • Loading branch information
arcanedev-maroc authored Mar 19, 2024
2 parents e4f3797 + 4028ab5 commit c9a1407
Show file tree
Hide file tree
Showing 45 changed files with 660 additions and 550 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
phpunit.xml.dist export-ignore
CONTRIBUTING.md export-ignore
phpunit.xml.dist export-ignore
pint.json export-ignore
23 changes: 23 additions & 0 deletions .github/workflows/cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check & Fix styling

on: [push]

jobs:
cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: "laravel-pint"
uses: aglipanci/laravel-pint-action@latest
with:
verboseMode: true

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix the code styling
7 changes: 0 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Cache dependencies
uses: actions/cache@v2
Expand All @@ -38,8 +36,3 @@ jobs:

- name: Execute tests
run: composer test:ci

- name: Scrutinizer CI
run: |
composer require scrutinizer/ocular --dev
vendor/bin/ocular code-coverage:upload --format=php-clover /build/coverage/clover.xml
35 changes: 0 additions & 35 deletions .scrutinizer.yml

This file was deleted.

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"require-dev": {
"ext-dom": "*",
"laravel/pint": "^1.14",
"phpunit/phpunit": "^10.5|^11.0"
},
"autoload": {
Expand All @@ -35,7 +36,9 @@
"test": "phpunit --colors=always",
"test:dox": "phpunit --testdox --colors=always",
"test:cov": "phpunit --coverage-html",
"test:ci": "phpunit --coverage-text"
"test:ci": "phpunit --coverage-text",
"cs:fix": "pint -v",
"cs:test": "pint --test -v"
},
"extra": {
"branch-alias": {
Expand Down
85 changes: 85 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"preset": "per",
"rules": {
"align_multiline_comment": true,
"array_indentation": true,
"array_syntax": true,
"blank_line_after_namespace": true,
"blank_line_after_opening_tag": true,
"combine_consecutive_issets": true,
"combine_consecutive_unsets": true,
"concat_space": {
"spacing": "one"
},
"declare_parentheses": true,
"declare_strict_types": true,
"explicit_string_variable": true,
"fully_qualified_strict_types": true,
"global_namespace_import": {
"import_classes": true,
"import_constants": true,
"import_functions": true
},
"is_null": true,
"lambda_not_used_import": true,
"logical_operators": true,
"mb_str_functions": true,
"method_chaining_indentation": true,
"modernize_strpos": true,
"new_with_braces": true,
"no_empty_comment": true,
"not_operator_with_space": true,
"ordered_traits": true,
"protected_to_private": true,
"simplified_if_return": true,
"strict_comparison": true,
"ternary_to_null_coalescing": true,
"trim_array_spaces": true,
"use_arrow_functions": true,
"void_return": true,
"yoda_style": {
"always_move_variable": true,
"equal": false,
"identical": false,
"less_and_greater": false
},
"array_push": true,
"assign_null_coalescing_to_coalesce_equal": true,
"explicit_indirect_variable": true,
"method_argument_space": {
"on_multiline": "ensure_fully_multiline"
},
"modernize_types_casting": true,
"no_superfluous_elseif": true,
"no_useless_else": true,
"nullable_type_declaration_for_default_null_value": true,
"ordered_imports": {
"sort_algorithm": "alpha"
},
"ordered_class_elements": {
"order": [
"use_trait",
"case",
"constant",
"constant_public",
"constant_protected",
"constant_private",
"property_public",
"property_protected",
"property_private",
"construct",
"destruct",
"magic",
"phpunit",
"method_abstract",
"method_public_static",
"method_public",
"method_protected_static",
"method_protected",
"method_private_static",
"method_private"
],
"sort_algorithm": "none"
}
}
}
6 changes: 3 additions & 3 deletions src/Contracts/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function label(mixed $content = null, ?string $for = null): Label;
/**
* Make a legend tag.
*/
public function legend(HtmlElement|string $content = null): Legend;
public function legend(HtmlElement|string|null $content = null): Legend;

/**
* Make a mailto link.
Expand Down Expand Up @@ -171,7 +171,7 @@ public function radio(?string $name = null, ?bool $checked = null, mixed $value
* Make a range input.
*/
public function range(
string $name = null,
?string $name = null,
mixed $value = null,
mixed $min = null,
mixed $max = null,
Expand All @@ -196,7 +196,7 @@ public function span(mixed $content = null): Span;
/**
* Make a submit button.
*/
public function submit(string $text = null): Button;
public function submit(?string $text = null): Button;

/**
* Make a tel link.
Expand Down
8 changes: 5 additions & 3 deletions src/Elements/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ class Button extends HtmlElement
| -----------------------------------------------------------------
*/

use HasNameAttribute,
HasTypeAttribute,
HasValueAttribute;
use HasNameAttribute;

use HasTypeAttribute;

use HasValueAttribute;

/* -----------------------------------------------------------------
| Properties
Expand Down
30 changes: 16 additions & 14 deletions src/Elements/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getAttributes(): Attributes
*/
public function initAttributes(): static
{
$this->attributes = new Attributes;
$this->attributes = new Attributes();

return $this;
}
Expand All @@ -61,7 +61,7 @@ public function initAttributes(): static
*/
public function attribute(string $name, mixed $value = null): static
{
return tap(clone $this, function (HtmlElement $elt) use ($name, $value) {
return tap(clone $this, function (HtmlElement $elt) use ($name, $value): void {
$elt->getAttributes()->set($name, $value);
});
}
Expand All @@ -73,7 +73,7 @@ public function attribute(string $name, mixed $value = null): static
*/
public function attributes(iterable $attributes): static
{
return tap(clone $this, function (HtmlElement $elt) use ($attributes) {
return tap(clone $this, function (HtmlElement $elt) use ($attributes): void {
$elt->getAttributes()->setMany($attributes);
});
}
Expand All @@ -85,10 +85,11 @@ public function attributes(iterable $attributes): static
*/
public function forgetAttribute(string $name): static
{
if ( ! $this->hasAttribute($name))
if ( ! $this->hasAttribute($name)) {
return $this;
}

return tap(clone $this, function (self $elt) use ($name) {
return tap(clone $this, function (self $elt) use ($name): void {
$elt->getAttributes()->forget($name);
});
}
Expand All @@ -104,21 +105,22 @@ public function getAttribute(string $name, mixed $default = null): mixed
}

/**
* Get the attribute's value.
* Check if attribute exists.
*/
protected function getAttributeValue(string $name): ?string
public function hasAttribute(string $attribute): bool
{
if (! $this->hasAttribute($name))
return null;

return $this->getAttribute($name)->value();
return $this->getAttributes()->has($attribute);
}

/**
* Check if attribute exists.
* Get the attribute's value.
*/
public function hasAttribute(string $attribute): bool
protected function getAttributeValue(string $name): ?string
{
return $this->getAttributes()->has($attribute);
if ( ! $this->hasAttribute($name)) {
return null;
}

return $this->getAttribute($name)->value();
}
}
11 changes: 6 additions & 5 deletions src/Elements/Concerns/HasChildElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function setChildren(ChildrenCollection $children): static
*/
public function initChildren(): static
{
return $this->setChildren(new ChildrenCollection);
return $this->setChildren(new ChildrenCollection());
}

/**
Expand All @@ -82,10 +82,11 @@ public function children(mixed $children, ?Closure $mapper = null): static
*/
public function addChild(mixed $child, ?Closure $mapper = null): static
{
if (is_null($child))
if ($child === null) {
return $this;
}

return tap(clone $this, function (HtmlElement $elt) use ($child, $mapper) {
return tap(clone $this, function (HtmlElement $elt) use ($child, $mapper): void {
$elt->setChildren(
$elt->getChildren()->merge(ChildrenCollection::parse($child, $mapper))
);
Expand All @@ -97,7 +98,7 @@ public function addChild(mixed $child, ?Closure $mapper = null): static
*
* @return $this
*/
public function setNewChildren(mixed $children, Closure $mapper = null): static
public function setNewChildren(mixed $children, ?Closure $mapper = null): static
{
return tap(clone $this)
->initChildren()
Expand All @@ -121,7 +122,7 @@ public function prependChild(mixed $children, ?Closure $mapper = null): static
*/
public function prependChildren(mixed $children, ?Closure $mapper = null): static
{
return tap(clone $this, function (HtmlElement $elt) use ($children, $mapper) {
return tap(clone $this, function (HtmlElement $elt) use ($children, $mapper): void {
$elt->getChildren()
->prepend(ChildrenCollection::parse($children, $mapper));
});
Expand Down
6 changes: 3 additions & 3 deletions src/Elements/Concerns/HasConditionalMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function unless(bool $condition, Closure $callback): mixed
*/
public function ifNotNull(mixed $value, Closure $callback): mixed
{
return $this->if( ! is_null($value), $callback);
return $this->if($value !== null, $callback);
}

/* -----------------------------------------------------------------
Expand All @@ -81,8 +81,8 @@ protected function callConditionalMethod(string $conditions, string $method, arr
$callback = fn(): self => $this->{$method}(...$arguments);

return match ($conditions) {
'If' => $this->if((bool)$value, $callback),
'Unless' => $this->unless((bool)$value, $callback),
'If' => $this->if((bool) $value, $callback),
'Unless' => $this->unless((bool) $value, $callback),
'IfNotNull' => $this->ifNotNull($value, $callback),
default => $this,
};
Expand Down
17 changes: 9 additions & 8 deletions src/Elements/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@
class File extends HtmlElement
{
/* -----------------------------------------------------------------
| Constants
| Traits
| -----------------------------------------------------------------
*/

const ACCEPT_AUDIO = 'audio/*';
const ACCEPT_VIDEO = 'video/*';
const ACCEPT_IMAGE = 'image/*';
use HasAutofocusAttribute;

use HasNameAttribute;

use HasRequiredAttribute;
/* -----------------------------------------------------------------
| Traits
| Constants
| -----------------------------------------------------------------
*/

use HasAutofocusAttribute,
HasNameAttribute,
HasRequiredAttribute;
public const ACCEPT_AUDIO = 'audio/*';
public const ACCEPT_VIDEO = 'video/*';
public const ACCEPT_IMAGE = 'image/*';

/* -----------------------------------------------------------------
| Properties
Expand Down
Loading

0 comments on commit c9a1407

Please sign in to comment.