Skip to content

Commit

Permalink
Merge branch 'fixing-cs'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnugat committed Dec 14, 2024
2 parents 571ee14 + 8de139b commit 4b840e2
Show file tree
Hide file tree
Showing 28 changed files with 139 additions and 113 deletions.
98 changes: 9 additions & 89 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,92 +1,12 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('bin')
->exclude('cache')
->exclude('doc')
->exclude('logs')
->exclude('vendor')
;

return (new PhpCsFixer\Config())
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
'@Symfony' => true,

'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short',
],
'trailing_comma_in_multiline' => [
'elements' => ['arrays', 'arguments', 'parameters'],
],
'dir_constant' => true,
'ereg_to_preg' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'fopen_flag_order' => true,
'single_line_comment_style' => [
'comment_types' => ['hash'],
],
'heredoc_indentation' => true,
'heredoc_to_nowdoc' => true,
'implode_call' => true,
'is_null' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => [
'syntax' => 'short',
],
'logical_operators' => true,
'method_chaining_indentation' => true,
'modernize_types_casting' => true,
'multiline_whitespace_before_semicolons' => true,
'no_alias_functions' => true,
'no_alternative_syntax' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'echo_tag_syntax' => [
'format' => 'long',
],
'no_superfluous_elseif' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_cast' => true,
'no_unset_on_property' => true,
'no_useless_else' => true,
'ordered_class_elements' => true,
'ordered_interfaces' => true,
'php_unit_expectation' => true,
'php_unit_method_casing' => [
'case' => 'snake_case',
],
'php_unit_mock_short_will_return' => true,
'php_unit_namespaced' => true,
'php_unit_no_expectation_annotation' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'php_unit_test_annotation' => [
'style' => 'annotation',
],
'php_unit_test_case_static_method_calls' => [
'call_type' => 'self',
],
'pow_to_exponentiation' => true,
'protected_to_private' => true,
'psr_autoloading' => true,
'self_accessor' => true,
'set_type_to_cast' => true,
'simple_to_complex_string_variable' => true,
'static_lambda' => true,
'strict_comparison' => true,
'strict_param' => true,
'ternary_to_null_coalescing' => true,
'visibility_required' => [
'elements' => ['property', 'const'],
],
'void_return' => true,
'declare_strict_types' => true,
])
->setUsingCache(true)
->setFinder($finder)
return \Ssc\Cs\ConfigBuilder::forPath(__DIR__)
->withLicenseHeader(\Ssc\Cs\Factory\LicenseHeader::forPackage(
name: 'ssc/lib',
owners: [[
'name' => 'Loïc Faugeron',
'email' => '[email protected]',
]],
))
->build()
;
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 0.0.5: Tidied up project

* Configured and Applied `ssc/cs` in all of `ssc/lib`
* Fixed documentation typo
* Updated couscous

## 0.0.4: Created `ssc/cs`

Shared Coding Standards configuration, for SSC.
Expand Down
23 changes: 20 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ git push -f origin <your-branch>

Your pull request will be automatically updated.

## Monorepo Maintainance
## Monorepo Maintenance

Instead of managing X packages each in their own repo, they're all being managed in `ssc/lib`, as a monorepo.

To help maintain the monorepo, we use the tool [monorepo-builder](https://github.com/symplify/monorepo-builder).

### bump-interdependency

When releasing a version for the monorepo (eg `4.0`), and we need tu bump the packages that depend on it to version `^4.0`:
When releasing a version for the monorepo (eg `4.0`), and we need to bump the packages that depend on it to version `^4.0`:

```console
vendor/bin/monorepo-builder bump-interdependency "^4.0"
Expand Down Expand Up @@ -116,14 +116,18 @@ Next, create a new folder in `./packages` with the following tree structure:

```
./packages/exception/
├── .gitignore
├── .php-cs-fixer.dist.php
├── composer.json
├── phpspec.yml.dist
├── LICENSE
├── README.md
├── bin/test.sh
├── spec/
└── src/
```

Then, add a section in the root `phpspec.yml`:
Then, add a section in the root `phpspec.yml.dist`:

```yaml
suites:
Expand Down Expand Up @@ -182,6 +186,19 @@ throw NotFoundException::make('No Product found for ID 42')
[...]
```
Almost done, make sure to update couscous:
```yaml
menu:
items:
home:
text: Home
relativeUrl:
exception:
text: exception
relativeUrl: packages/exception/README.html
``
Finally, add library to `.github/workflows/split_monorepo.yaml`:
```yaml
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Decoupled PHP libraries.

> _Note_: `ssc/lib` is a **monorepo**, it is not possbile to install it in your projects.
> _Note_: `ssc/lib` is a **monorepo**, it is not possible to install it in your projects.
> It contains the code for multiple packages, this is where the changes for these are done.
> Each package can be installed, individually, in your projects (eg `composer require `ssc/<sub-package>`).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"friendsofphp/php-cs-fixer": "^3.65",
"phpspec/phpspec": "^7.5",
"phpspec/prophecy-phpunit": "^2.3",
"phpunit/phpunit": "^10.5.38",
"phpunit/phpunit": "^10.5.39",
"ssc/cs": "*@dev",
"symplify/monorepo-builder": "^11.2.22"
},
Expand Down
6 changes: 6 additions & 0 deletions couscous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ menu:
home:
text: Home
relativeUrl:
cs:
text: cs
relativeUrl: packages/cs/README.html
exception:
text: exception
relativeUrl: packages/exception/README.html
9 changes: 9 additions & 0 deletions monorepo-builder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use Symplify\MonorepoBuilder\Config\MBConfig;
Expand Down
2 changes: 1 addition & 1 deletion packages/cs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ with default for the SSC projects.
## Installation

```console
composer require ssc/cs
composer require --dev ssc/cs
```

Configure in `.php-cs-fixer.dist.php`:
Expand Down
6 changes: 6 additions & 0 deletions packages/cs/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"php": "^8.3",
"friendsofphp/php-cs-fixer": "^3.65"
},
"repositories": [
{
"type": "path",
"url": "../*"
}
],
"autoload": {
"psr-4": {
"Ssc\\Cs\\": "src"
Expand Down
4 changes: 2 additions & 2 deletions packages/cs/src/Factory/LicenseHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class LicenseHeader
{
private const DEFAULT_TEMPLATE = <<<'TPL'
This file is part of the {{ package_name }} package.
(c) {{ owner_name }} <{{ owner_email }}>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
TPL;
Expand Down
2 changes: 1 addition & 1 deletion packages/cs/src/Factory/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function make(): array
'elements' => ['property', 'const'],
],

// control_structures
// control_structures
'no_superfluous_elseif' => true, // SSC
'no_useless_else' => true, // SSC

Expand Down
12 changes: 12 additions & 0 deletions packages/exception/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

return \Ssc\Cs\ConfigBuilder::forPath(__DIR__)
->withLicenseHeader(\Ssc\Cs\Factory\LicenseHeader::forPackage(
name: 'ssc/lib',
owners: [[
'name' => 'Loïc Faugeron',
'email' => '[email protected]',
]],
))
->build()
;
43 changes: 43 additions & 0 deletions packages/exception/bin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash

SHORT_HELP="$0 [-h] [-f]'"

while getopts ":hf" opt; do
case $opt in
h)
echo 'Usage:'
echo " $SHORT_HELP"
echo ''
echo 'Options:'
echo ' -f Fix coding style'
echo ''
exit 0
;;
f)
echo ''
echo '// Fixing CS...'
echo ''

vendor/bin/php-cs-fixer fix --allow-risky=yes
exit 0
;;
\?)
echo '' >&2
echo " [KO] The \"-$OPTARG\" option does not exist" >&2
echo '' >&2
echo " $SHORT_HELP" >&2
echo '' >&2
exit 1
;;
esac
done
unset SHORT_HELP

echo ''
echo '// Running tests...'

composer --quiet dump --optimize

vendor/bin/phpspec --no-interaction run -fdot && \
# vendor/bin/phpunit && \
vendor/bin/php-cs-fixer fix --allow-risky=yes --dry-run
9 changes: 8 additions & 1 deletion packages/exception/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.65",
"phpspec/phpspec": "^7.5"
"phpspec/phpspec": "^7.5",
"ssc/cs": "*@dev"
},
"repositories": [
{
"type": "path",
"url": "../*"
}
],
"autoload": {
"psr-4": {
"Ssc\\Exception\\": "src"
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/spec/ClientErrorExceptionSpec.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/spec/ForbiddenExceptionSpec.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/spec/NotFoundExceptionSpec.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/spec/ServerErrorExceptionSpec.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/spec/SscExceptionSpec.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/spec/UnauthorizedExceptionSpec.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/spec/ValidationFailedExceptionSpec.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion packages/exception/src/ClientErrorException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/*
/**
* This file is part of the ssc/lib package.
*
* (c) Loïc Faugeron <[email protected]>
Expand Down
Loading

0 comments on commit 4b840e2

Please sign in to comment.