Skip to content

Commit bc30216

Browse files
committed
kick off
1 parent db6a186 commit bc30216

File tree

170 files changed

+106
-5526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+106
-5526
lines changed

.github/workflows/bare_run.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
php_version: ['7.4', '8.0', '8.1']
15+
php_version: ['7.4', '8.0', '8.2']
1616

1717
steps:
1818
- uses: shivammathur/setup-php@v2
1919
with:
2020
php-version: ${{ matrix.php }}
2121
coverage: none
2222

23-
- run: composer require rector/swiss-knife --dev --ansi
23+
- run: composer require behastan/behastan --dev --ansi

.github/workflows/code_analysis.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ jobs:
3232
name: 'Tests'
3333
run: vendor/bin/phpunit
3434

35-
-
36-
name: 'Check Commented Code'
37-
run: bin/swiss-knife check-commented-code src tests --ansi
38-
3935
-
4036
name: 'Check Active Classes'
4137
run: vendor/bin/class-leak check bin src --ansi

.github/workflows/downgraded_release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- run: cp -r build/target-repository/. .
4646

4747
# clear the dev files
48-
- run: rm -rf build prefix-code.sh full-tool-build.sh scoper.php rector.php rector-local
48+
- run: rm -rf build prefix-code.sh scoper.php rector.php rector-local
4949

5050
# setup git user
5151
-

README.md

Lines changed: 9 additions & 282 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Swiss Knife for Upgrades
1+
# Behastan - Modern Static analysis for Behat tests
22

3-
[![Downloads total](https://img.shields.io/packagist/dt/rector/swiss-knife.svg?style=flat-square)](https://packagist.org/packages/rector/swiss-knife/stats)
3+
[![Downloads total](https://img.shields.io/packagist/dt/behastan/behastan.svg?style=flat-square)](https://packagist.org/packages/behastan/behastan/stats)
44

55
Swiss knife in pocket of every upgrade architect!
66

@@ -9,187 +9,27 @@ Swiss knife in pocket of every upgrade architect!
99
## Install
1010

1111
```bash
12-
composer require rector/swiss-knife --dev
12+
composer require behastan/behastan --dev
1313
```
1414

15-
## Usage
15+
## Features
1616

17-
### 1. Check your Code for Git Merge Conflicts
17+
## 1. Find duplicated definitions
1818

19-
Do you use Git? Then merge conflicts is not what you want in your code ever to see in pushed code:
19+
...
20+
@todo
2021

21-
```bash
22-
<<<<<<< HEAD
23-
````
24-
25-
Add this command to CI to spot these:
26-
27-
```bash
28-
vendor/bin/swiss-knife check-conflicts .
29-
```
30-
31-
<br>
32-
33-
### 2. Detect Commented Code
34-
35-
Have you ever forgot commented code in your code?
36-
37-
```php
38-
// foreach ($matches as $match) {
39-
// $content = str_replace($match[0], $match[2], $content);
40-
// }
41-
```
42-
43-
No more! Add this command to CI to spot these:
44-
45-
```bash
46-
vendor/bin/swiss-knife check-commented-code <directory>
47-
vendor/bin/swiss-knife check-commented-code packages --line-limit 5
48-
```
49-
50-
<br>
51-
52-
### 3. Reach full PSR-4
53-
54-
#### Find multiple classes in single file
55-
56-
To make PSR-4 work properly, each class must be in its own file. This command makes it easy to spot multiple classes in single file:
57-
58-
```bash
59-
vendor/bin/swiss-knife find-multi-classes src
60-
```
61-
62-
<br>
63-
64-
#### Update Namespace to match PSR-4 Root
65-
66-
Is your class in wrong namespace? Make it match your PSR-4 root:
67-
68-
```bash
69-
vendor/bin/swiss-knife namespace-to-psr-4 src --namespace-root "App\\"
70-
```
71-
72-
This will update all files in your `/src` directory, to starts with `App\\` and follow full PSR-4 path:
73-
74-
```diff
75-
# file path: src/Repository/TalkRepository.php
76-
77-
-namespace Model;
78-
+namespace App\Repository;
79-
80-
...
81-
```
82-
83-
<br>
84-
85-
### 4. Finalize classes without children
86-
87-
Do you want to finalize all classes that don't have children?
88-
89-
```bash
90-
vendor/bin/swiss-knife finalize-classes src tests
91-
```
92-
93-
Do you use mocks but not [bypass final](https://tomasvotruba.com/blog/2019/03/28/how-to-mock-final-classes-in-phpunit) yet?
94-
95-
```bash
96-
vendor/bin/swiss-knife finalize-classes src tests --skip-mocked
97-
```
98-
99-
This will keep mocked classes non-final, so PHPUnit can extend them internally.
100-
101-
<br>
102-
103-
Do you want to skip file or two?
104-
105-
```bash
106-
vendor/bin/swiss-knife finalize-classes src tests --skip-file src/SpecialProxy.php
107-
```
108-
109-
<br>
110-
111-
### 5. Privatize local class constants
112-
113-
PHPStan can report unused private class constants, but it skips all the public ones.
114-
Do you have lots of class constants, all of them public but want to narrow scope to privates?
115-
116-
```bash
117-
vendor/bin/swiss-knife privatize-constants src test
118-
```
119-
120-
This command will:
121-
122-
* find all class constant usages
123-
* scans classes and constants
124-
* makes those constant used locally `private`
125-
126-
That way all the constants not used outside will be made `private` safely.
127-
128-
<br>
129-
130-
### 6. Mock only constructor param you need with MockWire
131-
132-
Imagine there is a service that has 6 dependencies in `__construct()`:
133-
134-
```php
135-
final class RealClass
136-
{
137-
public function __construct(
138-
private readonly FirstService $firstService,
139-
private readonly SecondService $secondService,
140-
private readonly ThirdService $thirdService,
141-
private readonly FourthService $fourthService,
142-
private readonly FifthService $fifthService,
143-
private readonly SixthService $sixthService
144-
) {
145-
}
146-
}
147-
```
148-
149-
<br>
150-
151-
But we want to **mock only one of them**:
152-
153-
```php
154-
use Rector\SwissKnife\Testing\MockWire;
155-
156-
// pass a mock
157-
$thirdDependencyMock = $this->createMock(ThirdDependency::class);
158-
$thirdDependencyMock->method('someMethod')->willReturn('some value');
159-
160-
$realClass = MockWire::create(RealClass::class, [
161-
$thirdDependencyMock
162-
]);
163-
```
16422

16523
<br>
16624

167-
Or pass direct instance:
168-
169-
```php
170-
$realClass = MockWire::create(RealClass::class, [
171-
new ThirdDependency()
172-
]);
173-
```
174-
175-
The rest of argument will be mocked automatically.
176-
177-
This way we:
178-
179-
* can easily **change the class constructor**, without having burden of changing all the tests.
180-
* see what is really being used in the constructor
181-
* avoid any mock-mess clutter properties all over our test
182-
183-
<br>
184-
185-
## 7. Find unused Behat definitions with static analysis - Behastan
25+
## 2. Find unused Behat definitions with static analysis
18626

18727
Behat uses `@When()`, `@Then()` and `@Given()` annotations and their PHP 8 attribute alternatives to define method to be called in `*.feature` files. Sometimes test change and lines from `*.feature` files are deleted. But what about definitions?
18828

18929
This command helps you to spot definitions that are no longer needed. Just provide test directory (1 or more) and let it statically compare defined and used masks:
19030

19131
```bash
192-
vendor/bin/swiss-knife behastan tests
32+
vendor/bin/behastan unused-definitions tests
19333
```
19434

19535
@@ -218,119 +58,6 @@ tests/Behat/OrderContext.php
21858

21959
You can also add this command to CI, to get instant feedback about unused definitions.
22060

221-
<br>
222-
223-
## 8. Quick search PHP files with regex
224-
225-
Data beats guess. Do you need a quick idea how many files contain `$this->get('...')` calls? Or another anti-pattern you want to remove?
226-
227-
PhpStorm helps with similar search, but stops counting at 100+. To get exact data about your codebase, use this command:
228-
229-
```bash
230-
vendor/bin/swiss-knife search-regex "#this->get\((.*)\)#"
231-
```
232-
233-
234-
235-
```bash
236-
Going through 1053 *.php files
237-
Searching for regex: #this->get\((.*)\)#
238-
239-
1053/1053 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
240-
241-
* src/Controller/ProjectController.php: 15
242-
* src/Controller/OrderController.php: 5
243-
244-
245-
[OK] Found 20 cases in 2 files
246-
247-
```
248-
249-
250-
<br>
251-
252-
## 9. Convert Alice fixtures from YAML to PHP
253-
254-
The `nelmio/alice` package [allows to use PHP](https://github.com/nelmio/alice/blob/v2.3.0/doc/complete-reference.md#php) for test fixture definitions. It's much better format, because Rector and PHPStan can understand it.
255-
256-
But what if we have 100+ YAML files in our project?
257-
258-
```bash
259-
vendor/bin/swiss-knife convert-alice-yaml-to-php fixtures
260-
```
261-
262-
That's it!
263-
264-
<br>
265-
266-
## 10. Generate Symfony 5.3 configs builders
267-
268-
Symfony 5.3 introduced amazing [config builders](https://symfony.com/blog/new-in-symfony-5-3-config-builder-classes), but those classes are not available for IDE until used. To make it easier, we added a command that generates all config builder classes you project can use, in `/var/cache/Symfony`.
269-
270-
```bash
271-
vendor/bin/swiss-knife generate-symfony-config-builders
272-
```
273-
274-
That way IDE, PHPStan after adding those paths and Rector can understand your config files better.
275-
276-
<br>
277-
278-
## 11. Spots Fake Traits
279-
280-
What is trait has 5 lines and used in single service? We know it's better to e inlined, to empower IDE, Rector and PHPStan. But don't have time to worry about these details.
281-
282-
We made a command to automate this process and spot the traits most likely to be inlined:
283-
284-
```bash
285-
vendor/bin/swiss-knife spot-lazy-traits src
286-
```
287-
288-
<br>
289-
290-
By default, the commands look for traits used max 2-times. To change that:
291-
292-
```bash
293-
vendor/bin/swiss-knife spot-lazy-traits src --max-used 4
294-
```
295-
296-
That's it! Run this command once upon a time or run it in CI to eliminate traits with low value to exists. Your code will be more robuts and easier to work with.
297-
298-
299-
<br>
300-
301-
## 12. Mutual Private Repository Dependencies
302-
303-
Do you have a project that uses 5 private repositories? And another one that uses different 3 private repositories? Are their open-source dependencies up to date?
304-
305-
In such situations, we want to get a quick idea about the weakest link. Do all those repositories use the same version of "symfony/console"? What about their min PHP versions?
306-
307-
<br>
308-
309-
That's where `multi-package-composer-stats` comes. Feed it the links to dependency repositories you want to know versions for:
310-
311-
```bash
312-
vendor/bin/swiss-knife multi-package-composer-stats private-company/private-repository.git \
313-
private-company/another-private-repository.git
314-
```
315-
316-
317-
318-
<kbd>
319-
<img src="https://pbs.twimg.com/media/GhfcUmoXkAAFA1S?format=png" style="max-width:15em">
320-
</kbd>
321-
322-
<br>
323-
<br>
324-
<br>
325-
326-
Do you want to compare **the main projects** and themselves and fetch their dependencies automatically? Provide urls to the repositories and the `--is-source` option:
327-
328-
```bash
329-
vendor/bin/swiss-knife multi-package-composer-stats private-company/first-project.git \
330-
private-company/another-project.git
331-
```
332-
333-
Now all the dependencies are fetched per provided project from the `"repositories"` section of `composer.json`.
33461

33562
That's it!
33663

bin/behastan

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require __DIR__ . '/behastan.php';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\Console\Application;
66
use Symfony\Component\Console\Input\ArgvInput;
77
use Symfony\Component\Console\Output\ConsoleOutput;
8-
use Rector\SwissKnife\DependencyInjection\ContainerFactory;
8+
use Behastan\DependencyInjection\ContainerFactory;
99

1010
$possibleAutoloadPaths = [
1111
// dependency

bin/swiss-knife

Lines changed: 0 additions & 4 deletions
This file was deleted.

build/build-scoped.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ ls -l $RESULT_DIRECTORY
4545
note "Dumping Composer Autoload"
4646
composer dump-autoload --working-dir "$RESULT_DIRECTORY" --ansi --classmap-authoritative --no-dev
4747

48-
# make bin/swiss-knife runnable without "php"
49-
chmod 777 "$RESULT_DIRECTORY/bin/swiss-knife"
50-
chmod 777 "$RESULT_DIRECTORY/bin/swiss-knife.php"
48+
# make bin/behastan runnable without "php"
49+
chmod 777 "$RESULT_DIRECTORY/bin/behastan"
50+
chmod 777 "$RESULT_DIRECTORY/bin/behastan.php"
5151

5252
note "Finished"

build/target-repository/.github/workflows/bare_run.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
php-version: ${{ matrix.php_version }}
2121
coverage: none
2222

23-
- run: php bin/swiss-knife list --ansi
23+
- run: php bin/behastan list --ansi

0 commit comments

Comments
 (0)