Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub action #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Check & fix styling

on: [push]

jobs:
style:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Fix style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Commit changes
uses: stefanzweifel/[email protected]
with:
commit_message: Fix styling
branch: ${{ steps.extract_branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 changes: 33 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Psalm

on:
push:
paths:
- '**.php'
- 'psalm.xml.dist'

jobs:
psalm:
name: psalm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}

- name: Run composer install
run: composer install -n --prefer-dist

- name: Run psalm
run: ./vendor/bin/psalm --output-format=github
30 changes: 30 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: "Run Tests - Current"

on: [ push, pull_request ]

jobs:
test:
runs-on: ubuntu-latest

services:
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: test_db
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v1
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Composer Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
- name: Generate Key
run: php artisan key:generate
- name: Execute tests (Unit and Feature tests) via PHPUnit
env:
DB_PORT: ${{ job.services.mysql.ports[3306] }}
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ yarn-error.log
/.vscode
public/dist
resources/assets/js/routes.generated.js
.php-cs-fixer.cache
35 changes: 35 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__.'/app',
__DIR__.'/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
1 change: 0 additions & 1 deletion app/Application/Inertia/AppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class AppData implements InertiaDataSharable
{

public function key(): string
{
return 'app';
Expand Down
5 changes: 2 additions & 3 deletions app/Application/Inertia/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class Translations implements InertiaDataSharable
{

public function key(): string
{
return 'translations';
Expand All @@ -23,9 +22,9 @@ public function data(): Closure|array
{
return function () {
$translations = new TranslationCaching();
$locale = app()->getLocale();
$locale = app()->getLocale();

if ( app()->environment('local') ) {
if (app()->environment('local')) {
$translations->flush($locale);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function findByName(string $name): Module|array
$modules = $this->getBuilder()->where('name', $name)->get();

$this->resetModel();
if ( $modules->isEmpty() ) {
if ($modules->isEmpty()) {
throw new ModelNotFoundException();
}

Expand Down
10 changes: 5 additions & 5 deletions app/Domain/Users/Actions/Auth/RegisterNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public function create(array $input)

Validator::make($input, [
'full_name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', "unique:{$usersTable},email"],
'password' => $this->passwordRules(),
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['required', 'accepted'] : '',
'email' => ['required', 'string', 'email', 'max:255', "unique:{$usersTable},email"],
'password' => $this->passwordRules(),
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['required', 'accepted'] : '',
])->validate();

return tap(
app(UsersRepository::class)->create([
'full_name' => FullNameDto::fromString($input['full_name']),
'email' => $input['email'],
'password' => $input['password'],
'email' => $input['email'],
'password' => $input['password'],
]),
function (User $user) {
$user->assignRole(Jetstream::defaultRole());
Expand Down
17 changes: 8 additions & 9 deletions app/Domain/Users/Actions/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ class UpdateUserProfileInformation implements UpdatesUserProfileInformation
public function update($user, array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique(DBTables::AUTH_USERS)->ignore($user->id)],
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
])->validateWithBag('updateProfileInformation');

if ( isset($input['photo']) ) {
if (isset($input['photo'])) {
$user->updateProfilePhoto($input['photo']);
}

if ( $input['email'] !== $user->email &&
$user instanceof MustVerifyEmail ) {
if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
$this->updateVerifiedUser($user, $input);
}
else {
} else {
$user->forceFill([
'full_name' => FullNameDto::fromString($input['name']),
'email' => $input['email'],
'email' => $input['email'],
])->save();
}
}
Expand All @@ -55,8 +54,8 @@ public function update($user, array $input)
protected function updateVerifiedUser($user, array $input)
{
$user->forceFill([
'full_name' => FullNameDto::fromString($input['name']),
'email' => $input['email'],
'full_name' => FullNameDto::fromString($input['name']),
'email' => $input['email'],
'email_verified_at' => null,
])->save();

Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Users/Casts/FullNameCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function get($model, string $key, $value, array $attributes)
*/
public function set($model, string $key, $value, array $attributes)
{
if ( !$value instanceof FullNameDto ) {
if (! $value instanceof FullNameDto) {
throw new InvalidArgumentException('The given value is not an FullNameDto instance.');
}

Expand Down
22 changes: 11 additions & 11 deletions app/Domain/Users/DTO/FullNameDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@ public static function fromString(string $name): self
{
$explodedName = explode(' ', $name);

$firstName = array_shift($explodedName);
$lastName = array_pop($explodedName) ?? '';
$firstName = array_shift($explodedName);
$lastName = array_pop($explodedName) ?? '';
$middleName = count($explodedName) ? trim(implode(' ', $explodedName)) : '';

return new static([
'first_name' => $firstName,
'first_name' => $firstName,
'middle_name' => $middleName,
'last_name' => $lastName,
'last_name' => $lastName,
]);
}

public function toArray(): array
{
return [
'first_name' => $this->firstName,
'first_name' => $this->firstName,
'middle_name' => $this->middleName,
'last_name' => $this->lastName,
'last_name' => $this->lastName,
];
}

public function toString(): string
{
$fullName = [];
if ( $this->firstName ) {
if ($this->firstName) {
$fullName[] = $this->firstName;
}

if ( $this->middleName ) {
if ($this->middleName) {
$fullName[] = $this->middleName;
}

if ( $this->lastName ) {
if ($this->lastName) {
$fullName[] = $this->lastName;
}

Expand All @@ -60,8 +60,8 @@ public function toString(): string

protected function map(array $data): void
{
$this->firstName = Arr::get($data, 'first_name');
$this->firstName = Arr::get($data, 'first_name');
$this->middleName = Arr::get($data, 'middle_name');
$this->lastName = Arr::get($data, 'last_name');
$this->lastName = Arr::get($data, 'last_name');
}
}
1 change: 0 additions & 1 deletion app/Domain/Users/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
*/
class Permission extends BasePermission
{

}
1 change: 0 additions & 1 deletion app/Domain/Users/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
*/
class Role extends BaseRole
{

}
4 changes: 2 additions & 2 deletions app/Domain/Users/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class User extends Authenticatable
];

protected $casts = [
'full_name' => FullNameCast::class,
'full_name' => FullNameCast::class,
'two_factor_recovery_codes' => 'array',
];

Expand Down Expand Up @@ -112,7 +112,7 @@ protected static function newFactory()
public function setPasswordAttribute(string $password): void
{
/** @var HashManager $hashManager */
$hashManager = app()->make(HashManager::class);
$hashManager = app()->make(HashManager::class);
$this->attributes['password'] = $hashManager->needsRehash($password) ? $hashManager->make($password)
: $password;
}
Expand Down
1 change: 0 additions & 1 deletion app/Domain/Users/Repositories/PermissionsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
*/
interface PermissionsRepository extends RepositoryInterface
{

}
1 change: 0 additions & 1 deletion app/Domain/Users/Repositories/RolesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
*/
interface RolesRepository extends RepositoryInterface
{

}
1 change: 0 additions & 1 deletion app/Domain/Users/Repositories/UsersRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
*/
interface UsersRepository extends RepositoryInterface
{

}
18 changes: 9 additions & 9 deletions app/Enums/DBTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
enum DBTables
{
public const SYS_FAILED_JOBS = 'sys_failed_jobs';
public const SYS_SESSIONS = 'sys_sessions';
public const SYS_MIGRATIONS = 'sys_migrations';
public const SYS_MODULES = 'sys_modules';
public const SYS_SESSIONS = 'sys_sessions';
public const SYS_MIGRATIONS = 'sys_migrations';
public const SYS_MODULES = 'sys_modules';

public const AUTH_USERS = 'auth_users';
public const AUTH_USERS = 'auth_users';
public const AUTH_PASSWORD_RESETS = 'auth_password_resets';
public const AUTH_PERSONAL_ACCESS_TOKENS = 'auth_personal_access_tokens';
public const AUTH_ROLES = 'auth_roles';
public const AUTH_PERMISSIONS = 'auth_permissions';
public const AUTH_USERS_PERMISSIONS = 'auth_users_permissions';
public const AUTH_USERS_ROLES = 'auth_users_roles';
public const AUTH_ROLES_PERMISSIONS = 'auth_roles_permissions';
public const AUTH_ROLES = 'auth_roles';
public const AUTH_PERMISSIONS = 'auth_permissions';
public const AUTH_USERS_PERMISSIONS = 'auth_users_permissions';
public const AUTH_USERS_ROLES = 'auth_users_roles';
public const AUTH_ROLES_PERMISSIONS = 'auth_roles_permissions';
}
16 changes: 8 additions & 8 deletions app/Infrastructure/Kernels/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class HttpKernel extends Kernel
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \App\Infrastructure\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Infrastructure\Middleware\RedirectIfAuthenticated::class,
'auth' => \App\Infrastructure\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Infrastructure\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}
Loading