• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JBZoo / Codestyle / 18063683129

27 Sep 2025 06:57PM UTC coverage: 80.896% (-6.8%) from 87.66%
18063683129

push

github

web-flow
test(ci): Update PHP versions and fix workflow tests (#54)

- Update PHP versions in CI workflows from 8.1-8.3 to 8.2-8.4.
- Remove the unnecessary scheduled CI job.
- Adjust `TraitGithubActions` to validate the updated workflow
configuration.
- Fix badge line formatting in `TraitReadme` test.

4 of 4 new or added lines in 2 files covered. (100.0%)

79 existing lines in 7 files now uncovered.

542 of 670 relevant lines covered (80.9%)

10.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/src/PhpCsFixer/PhpCsFixerCodingStandard.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Codestyle.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Codestyle
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\Codestyle\PhpCsFixer;
18

19
use PhpCsFixer\Config;
20
use PhpCsFixer\ConfigInterface;
21
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
22
use PhpCsFixerCustomFixers\Fixer\NoDuplicatedArrayKeyFixer;
23
use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer;
24
use PhpCsFixerCustomFixers\Fixers;
25
use Symfony\Component\Finder\Finder;
26

27
/**
28
 * See details: https://mlocati.github.io/php-cs-fixer-configurator.
29
 */
30
final class PhpCsFixerCodingStandard
31
{
32
    private array $ruleSet = [
33
        // Presets
34
        '@Symfony'          => true,
35
        '@Symfony:risky'    => true,
36
        '@PhpCsFixer'       => true,
37
        '@PhpCsFixer:risky' => true,
38
        '@PSR12'            => true,
39
        '@PSR12:risky'      => true,
40

41
        // The most dangerous options! They are excluded from above presets. Just in case.
42
        'no_trailing_whitespace_in_string'      => false,
43
        'no_unneeded_final_method'              => false,
44
        'strict_comparison'                     => false, // TODO: Check ho many issues we have in real code.
45
        'error_suppression'                     => false, // TODO: Check ho many issues we have in real code.
46
        'no_unreachable_default_argument_value' => false, // TODO: Check ho many issues we have in real code.
47
        'no_unset_on_property'                  => false, // TODO: Check ho many issues we have in real code.
48

49
        // PHPDocs & Comments
50
        'align_multiline_comment'    => ['comment_type' => 'phpdocs_like'],
51
        'phpdoc_separation'          => false,
52
        'phpdoc_to_comment'          => false,
53
        'no_superfluous_phpdoc_tags' => [
54
            'allow_mixed'         => true,
55
            'allow_unused_params' => true,
56
        ],
57
        'phpdoc_line_span' => [
58
            'const'    => 'single',
59
            'property' => 'single',
60
            'method'   => 'multi',
61
        ],
62

63
        // PHPUnit
64
        'php_unit_internal_class'                => false,
65
        'php_unit_strict'                        => false,
66
        'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
67
        'php_unit_test_class_requires_covers'    => false,
68

69
        // Import & ordering rules
70
        'no_unused_imports'                => true,
71
        'blank_line_between_import_groups' => true,
72
        'fully_qualified_strict_types'     => true,
73
        'global_namespace_import'          => [
74
            'import_classes'   => false,
75
            'import_constants' => false,
76
            'import_functions' => false,
77
        ],
78
        'ordered_imports' => [
79
            'sort_algorithm' => 'alpha',
80
            'imports_order'  => ['class', 'function', 'const'],
81
        ],
82
        'ordered_interfaces'     => ['direction' => 'ascend', 'order' => 'alpha'],
83
        'ordered_class_elements' => [
84
            'order' => [
85
                'use_trait',
86
                'case',
87
                // Const
88
                'constant',
89
                'constant_public',
90
                'constant_protected',
91
                'constant_private',
92
                // Props
93
                'property',
94
                'property_public_static',
95
                'property_protected_static',
96
                'property_private_static',
97
                'property_public',
98
                'property_protected',
99
                'property_private',
100
                // Statics
101
                'method_public_abstract_static',
102
                'method_protected_abstract_static',
103
                'method_public_abstract',
104
                'method_protected_abstract',
105
                // Magic methods
106
                'construct',
107
                'destruct',
108
                'magic',
109
                'phpunit',
110
                // Regular Methods
111
                'method',
112
                'method_public',
113
                'method_public_static',
114
                'method_protected',
115
                'method_protected_static',
116
                'method_private',
117
                'method_private_static',
118
            ],
119
        ],
120

121
        'binary_operator_spaces' => [
122
            'operators' => [
123
                '='  => 'align_single_space_minimal',
124
                '=>' => 'align_single_space_minimal',
125
            ],
126
        ],
127

128
        'type_declaration_spaces' => ['elements' => ['function']],
129

130
        // Blank lines & spaces
131
        'cast_spaces'  => ['space' => 'none'],
132
        'types_spaces' => ['space' => 'none'],
133
        'concat_space' => ['spacing' => 'one'],
134

135
        'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
136
        'trailing_comma_in_multiline'            => [
137
            'after_heredoc' => true,
138
            'elements'      => ['arrays', 'arguments', 'parameters'],
139
        ],
140

141
        'blank_line_before_statement' => [
142
            'statements' => [
143
                'case',
144
                'default',
145
                'declare',
146
                'do',
147
                'for',
148
                'foreach',
149
                'return',
150
                'switch',
151
                'try',
152
                'while',
153
                'phpdoc',
154
            ],
155
        ],
156

157
        'no_extra_blank_lines' => [
158
            'tokens' => [
159
                'attribute',
160
                'break',
161
                'case',
162
                'continue',
163
                'curly_brace_block',
164
                'default',
165
                'extra',
166
                'parenthesis_brace_block',
167
                'return',
168
                'square_brace_block',
169
                'switch',
170
                'throw',
171
                'use',
172
            ],
173
        ],
174

175
        'single_space_around_construct'           => true,
176
        'control_structure_braces'                => true,
177
        'braces_position'                         => true,
178
        'control_structure_continuation_position' => true,
179
        'declare_parentheses'                     => true,
180
        'statement_indentation'                   => true,
181
        'no_multiple_statements_per_line'         => true,
182
        'method_chaining_indentation'             => true,
183

184
        // Extra rules
185
        'increment_style' => ['style' => 'post'],
186
        'yoda_style'      => [
187
            'equal'            => true,
188
            'identical'        => false,
189
            'less_and_greater' => false,
190
        ],
191
        'regular_callable_call'      => true,
192
        'self_static_accessor'       => true,
193
        'simplified_if_return'       => true,
194
        'static_lambda'              => true,
195
        'native_function_invocation' => [
196
            'scope'   => 'all',
197
            'strict'  => true,
198
            'include' => ['@internal'],
199
        ],
200
        'native_constant_invocation' => [
201
            'fix_built_in' => true,
202
            'include'      => [
203
                'DIRECTORY_SEPARATOR',
204
                'PHP_INT_SIZE',
205
                'PHP_SAPI',
206
                'PHP_VERSION_ID',
207
            ],
208
            'scope'  => 'all',
209
            'strict' => true,
210
        ],
211

212
        'nullable_type_declaration_for_default_null_value' => true,
213

214
        'single_line_empty_body' => false,
215

216
        // For the future
217
        // 'final_class' => true
218
    ];
219

220
    private string $projectPath;
221
    private string $styleName = 'JBZooStyle';
222

223
    public function __construct(string $projectPath)
224
    {
225
        $path = \realpath($projectPath);
12✔
226

227
        if ($path === false) {
12✔
UNCOV
228
            throw new \RuntimeException("Project path \"{$projectPath}\" is not valid");
×
229
        }
230

231
        $this->projectPath = $path;
12✔
232
    }
233

234
    public function getRules(): array
235
    {
236
        return $this->ruleSet;
12✔
237
    }
238

239
    public function getFixerConfig(
240
        ?Finder $customFinder = null,
241
        array $customRules = [],
242
        bool $inheritRuleSet = true,
243
    ): ConfigInterface {
244
        if ($inheritRuleSet) {
12✔
245
            $customRules = [
12✔
246
                NoDuplicatedArrayKeyFixer::name() => true,
12✔
247
                NoUselessCommentFixer::name()     => true,
12✔
248
            ] + $customRules;
12✔
249

250
            $all = self::mergeRules($this->getRules(), $customRules);
12✔
251
        } else {
UNCOV
252
            $all = $customRules;
×
253
        }
254

255
        return (new Config($this->styleName))
12✔
256
            ->setParallelConfig(ParallelConfigFactory::detect())
12✔
257
            ->setRiskyAllowed(true)
12✔
258
            ->registerCustomFixers(new Fixers())
12✔
259
            ->setCacheFile("{$this->projectPath}/build/php-cs-fixer-cache.json")
12✔
260
            ->setFinder($customFinder ?? $this->getFinder())
12✔
261
            ->setRules($all);
12✔
262
    }
263

264
    public function getFinder(): Finder
265
    {
266
        return (new Finder())
12✔
267
            ->files()
12✔
268
            ->followLinks()
12✔
269
            ->ignoreVCS(true)
12✔
270
            ->ignoreDotFiles(false)
12✔
271
            ->in($this->projectPath)
12✔
272
            ->exclude('vendor')
12✔
273
            ->exclude('build')
12✔
274
            ->name('/\.php$/');
12✔
275
    }
276

277
    private static function mergeRules(array $original, array $overrides): array
278
    {
279
        foreach ($overrides as $newKey => $newValue) {
12✔
280
            if (isset($original[$newKey]) && $newValue === null) {
12✔
UNCOV
281
                unset($original[$newKey]);
×
282
                continue;
×
283
            }
284

285
            $original[$newKey] = $newValue;
12✔
286
        }
287

288
        return $original;
12✔
289
    }
290
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc