Skip to content

Commit

Permalink
PHPCS check and workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatosbc committed Dec 23, 2024
1 parent 5b1b570 commit 07f089e
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 4 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/composer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: PHP Composer

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

# - name: Run test suite
# run: composer run-script test
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PHP Lint

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
php-version: ['8.2']

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- name: Install PHP_CodeSniffer
run: composer global require "squizlabs/php_codesniffer=*"

- name: Run PHP_CodeSniffer
run: ~/.composer/vendor/bin/phpcs

- name: Upload PHP_CodeSniffer results
if: always()
uses: actions/upload-artifact@v4
with:
name: phpcs-results
path: phpcs.xml

- name: Display PHP_CodeSniffer results
if: always()
run: cat phpcs.xml
28 changes: 28 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PHPUnit Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2' # PHP version updated to 8.2
extensions: mbstring, intl
coverage: xdebug # If you need code coverage

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPUnit
run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion .phpcs-cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"config":{"phpVersion":80226,"phpExtensions":"6444a8d24aa127a4fe13989038fc4447","tabWidth":4,"encoding":"utf-8","recordErrors":true,"annotations":true,"configData":[],"codeHash":"b5dc58ae9d1a395f86384fd9a1678bb4","rulesetHash":"670f8348153700c3a70fc6127ca0e484"},"\/home\/carlos\/Projects\/factory\/src\/Exceptions\/ClassNotFoundException.php":{"hash":"ef42127b99db182750f3cb885f5a00a233204","errors":[],"warnings":[],"metrics":{"Declarations and side effects mixed":{"values":{"no":1}},"PHP short open tag used":{"values":{"no":1}},"EOL char":{"values":{"\\n":1}},"Number of newlines at EOF":{"values":{"1":1}},"PHP closing tag at end of PHP-only file":{"values":{"no":1}},"Line length":{"values":{"80 or less":5}},"PHP keyword case":{"values":{"lower":3}},"Multiple statements on same line":{"values":{"no":1}},"One class per file":{"values":{"yes":1}},"Class defined in namespace":{"values":{"yes":1}},"PascalCase class name":{"values":{"yes":1}},"Class opening brace placement":{"values":{"new line":1}}},"errorCount":0,"warningCount":0,"fixableCount":0,"numTokens":23},"\/home\/carlos\/Projects\/factory\/src\/Exceptions\/ServiceNotFoundException.php":{"hash":"fd4d95418d462fa9339b8f96cf301a7533204","errors":[],"warnings":[],"metrics":{"Declarations and side effects mixed":{"values":{"no":1}},"PHP short open tag used":{"values":{"no":1}},"EOL char":{"values":{"\\n":1}},"Number of newlines at EOF":{"values":{"1":1}},"PHP closing tag at end of PHP-only file":{"values":{"no":1}},"Line length":{"values":{"80 or less":5}},"PHP keyword case":{"values":{"lower":3}},"Multiple statements on same line":{"values":{"no":1}},"One class per file":{"values":{"yes":1}},"Class defined in namespace":{"values":{"yes":1}},"PascalCase class name":{"values":{"yes":1}},"Class opening brace placement":{"values":{"new line":1}}},"errorCount":0,"warningCount":0,"fixableCount":0,"numTokens":23},"\/home\/carlos\/Projects\/factory\/src\/ServiceFactory.php":{"hash":"56e242256f0874adfa49963d1503e82333204","errors":[],"warnings":[],"metrics":{"Declarations and side effects mixed":{"values":{"no":1}},"PHP short open tag used":{"values":{"no":1}},"EOL char":{"values":{"\\n":1}},"Number of newlines at EOF":{"values":{"1":1}},"PHP closing tag at end of PHP-only file":{"values":{"no":1}},"Line length":{"values":{"80 or less":77,"81-120":11}},"Line indent":{"values":{"spaces":81}},"PHP keyword case":{"values":{"lower":51}},"Multiple statements on same line":{"values":{"no":25}},"One class per file":{"values":{"yes":1}},"Class defined in namespace":{"values":{"yes":1}},"PascalCase class name":{"values":{"yes":1}},"Class opening brace placement":{"values":{"new line":1}},"PHP type case":{"values":{"lower":19}},"CamelCase method name":{"values":{"yes":5}},"Function opening brace placement":{"values":{"new line":5}},"Spaces after control structure open parenthesis":{"values":[8]},"Spaces before control structure close parenthesis":{"values":[8]},"Blank lines at start of control structure":{"values":[8]},"Blank lines at end of control structure":{"values":[8]},"Control structure defined inline":{"values":{"no":7}},"PHP constant case":{"values":{"lower":5}}},"errorCount":0,"warningCount":0,"fixableCount":0,"numTokens":757}}
{"config":{"phpVersion":80226,"phpExtensions":"6444a8d24aa127a4fe13989038fc4447","tabWidth":4,"encoding":"utf-8","recordErrors":true,"annotations":true,"configData":[],"codeHash":"b5dc58ae9d1a395f86384fd9a1678bb4","rulesetHash":"670f8348153700c3a70fc6127ca0e484"},"\/home\/carlos\/Projects\/factory\/src\/Exceptions\/ClassNotFoundException.php":{"hash":"ef42127b99db182750f3cb885f5a00a233204","errors":[],"warnings":[],"metrics":{"Declarations and side effects mixed":{"values":{"no":1}},"PHP short open tag used":{"values":{"no":1}},"EOL char":{"values":{"\\n":1}},"Number of newlines at EOF":{"values":{"1":1}},"PHP closing tag at end of PHP-only file":{"values":{"no":1}},"Line length":{"values":{"80 or less":5}},"PHP keyword case":{"values":{"lower":3}},"Multiple statements on same line":{"values":{"no":1}},"One class per file":{"values":{"yes":1}},"Class defined in namespace":{"values":{"yes":1}},"PascalCase class name":{"values":{"yes":1}},"Class opening brace placement":{"values":{"new line":1}}},"errorCount":0,"warningCount":0,"fixableCount":0,"numTokens":23},"\/home\/carlos\/Projects\/factory\/src\/Exceptions\/ServiceNotFoundException.php":{"hash":"fd4d95418d462fa9339b8f96cf301a7533204","errors":[],"warnings":[],"metrics":{"Declarations and side effects mixed":{"values":{"no":1}},"PHP short open tag used":{"values":{"no":1}},"EOL char":{"values":{"\\n":1}},"Number of newlines at EOF":{"values":{"1":1}},"PHP closing tag at end of PHP-only file":{"values":{"no":1}},"Line length":{"values":{"80 or less":5}},"PHP keyword case":{"values":{"lower":3}},"Multiple statements on same line":{"values":{"no":1}},"One class per file":{"values":{"yes":1}},"Class defined in namespace":{"values":{"yes":1}},"PascalCase class name":{"values":{"yes":1}},"Class opening brace placement":{"values":{"new line":1}}},"errorCount":0,"warningCount":0,"fixableCount":0,"numTokens":23},"\/home\/carlos\/Projects\/factory\/src\/ServiceFactory.php":{"hash":"8af11ef2a53563eb49f1e8f2415d9a7b33204","errors":{"125":{"13":[{"message":"No blank line found after control structure","source":"Squiz.WhiteSpace.ControlStructureSpacing.NoLineAfterClose","listener":"PHP_CodeSniffer\\Standards\\Squiz\\Sniffs\\WhiteSpace\\ControlStructureSpacingSniff","severity":0,"fixable":true}]}},"warnings":[],"metrics":{"Declarations and side effects mixed":{"values":{"no":1}},"PHP short open tag used":{"values":{"no":1}},"EOL char":{"values":{"\\n":1}},"Number of newlines at EOF":{"values":{"1":1}},"PHP closing tag at end of PHP-only file":{"values":{"no":1}},"Line length":{"values":{"80 or less":100,"81-120":11}},"Line indent":{"values":{"spaces":104}},"PHP keyword case":{"values":{"lower":64}},"Multiple statements on same line":{"values":{"no":26}},"One class per file":{"values":{"yes":1}},"Class defined in namespace":{"values":{"yes":1}},"PascalCase class name":{"values":{"yes":1}},"Class opening brace placement":{"values":{"new line":1}},"PHP type case":{"values":{"lower":19}},"CamelCase method name":{"values":{"yes":6}},"Function opening brace placement":{"values":{"new line":6}},"Spaces after control structure open parenthesis":{"values":[12]},"Spaces before control structure close parenthesis":{"values":[12]},"Blank lines at start of control structure":{"values":[13]},"Blank lines at end of control structure":{"values":[13]},"Control structure defined inline":{"values":{"no":10}},"PHP constant case":{"values":{"lower":8}}},"errorCount":1,"warningCount":0,"fixableCount":1,"numTokens":870}}
10 changes: 7 additions & 3 deletions src/ServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function associateCondition(string $serviceName, string $conditionName):

/**
* Evaluates all conditions for a service
*
*
* @throws \InvalidArgumentException When a condition is not met
*/
private function evaluateConditions(string $serviceName): \Generator
Expand All @@ -74,8 +74,12 @@ private function evaluateConditions(string $serviceName): \Generator

yield match ($result) {
true => true,
false => throw new \InvalidArgumentException("Condition '$conditionName' not met for service: $serviceName"),
default => throw new \InvalidArgumentException("Invalid result for condition '$conditionName' on service: $serviceName")
false => throw new \InvalidArgumentException(
"Condition '$conditionName' not met for service: $serviceName"
),
default => throw new \InvalidArgumentException(
"Invalid result for condition '$conditionName' on service: $serviceName"
)
};
}
}
Expand Down

0 comments on commit 07f089e

Please sign in to comment.