Skip to content

Commit 1577092

Browse files
committed
Updated README.md to reflect recent changes to the console output.
Added docs/Ruleset.md which serves as a reference to list all the potential rules that may trigger semantic versioning of code. Separated getLine from getLocation in the subclasses of Operation. This allows us to format the location using short/full path if we want to. Short path will be used by default when displaying on the console. Added logic in Reporter to format the location according to the optional input "full-path".
1 parent 11bfb67 commit 1577092

21 files changed

+316
-71
lines changed

README.md

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,86 @@ PHP Semantic Versioning Checker is a console/library which allows you to inspect
1010

1111
After the inspection is completed, you are given a list of changes that have occurred between the two changesets. For each of these changes, the level of the change (MAJOR, MINOR, PATCH, NONE) will be given, as well as the location of the change (file and line number) and a reason as to why this level change is suggested.
1212

13-
## Current checks & ruleset
14-
15-
- Functions
16-
- Function added -> **MINOR**
17-
- Function removed -> **MAJOR**
18-
- Function parameter mismatch -> **MAJOR**
19-
- Function implementation changed -> **PATCH**
20-
- Classes
21-
- Class added -> **MINOR**
22-
- Class removed -> **MAJOR**
23-
- Public class method added -> **MINOR**
24-
- Public class method removed -> **MAJOR**
25-
- Public class method parameter mismatch -> **MAJOR**
26-
- Public class method implementation changed -> **PATCH**
13+
## Getting started
14+
15+
As this is still an alpha package, it is not suggested to include `php-semver-checker` directly in your composer.phar. There are however a couple ways to use the tool:
16+
17+
1. `php composer.phar create-project tomzx/php-semver-checker --stability=dev` will clone to a new php-semver-checker folder in your current working directory
18+
2. `php composer.phar global require tomzx/php-semver-checker --stability=dev` will clone it to your global composer location, so you can use it from anywhere.
19+
3. `git clone https://github.com/tomzx/php-semver-checker.git` and `php composer.phar install` in the newly cloned directory.
20+
21+
As the package gets more stable, other means of distribution may become available (such as a .phar).
22+
23+
## Current ruleset & verification codes
24+
25+
See `docs/Ruleset.md` for an exhaustive list of currently supported (and to come) ruleset.
26+
27+
Verification codes are a mean to uniquely identify a semantic versioning trigger (a condition which upon detection, requires your code changes to be versioned).
2728

2829
## Example
2930

3031
```bash
31-
php bin/php-semver-checker compare factory-muffin-1.6.4 factory-muffin-2.0.0
32+
php bin/php-semver-checker compare tests/fixtures/before tests/fixtures/after
3233

3334
Suggested semantic versioning change: MAJOR
3435

35-
Class
36-
+-------+-------------------------------------------------------------------------------------------------------------------+--------------------+
37-
| Level | Location | Reason |
38-
+-------+-------------------------------------------------------------------------------------------------------------------+--------------------+
39-
| MAJOR | src/Zizaco/FactoryMuff/Facade/FactoryMuff.php#8 Zizaco\FactoryMuff\Facade\FactoryMuff | Class was removed. |
40-
| MAJOR | src/Zizaco/FactoryMuff/FactoryMuff.php#13 Zizaco\FactoryMuff\FactoryMuff | Class was removed. |
41-
| MAJOR | src/Zizaco/FactoryMuff/Kind.php#7 Zizaco\FactoryMuff\Kind | Class was removed. |
42-
[...]
43-
| MINOR | src/Exceptions/DeleteFailedException.php#17 League\FactoryMuffin\Exceptions\DeleteFailedException | Class was added. |
44-
| MINOR | src/Exceptions/DeleteMethodNotFoundException.php#17 League\FactoryMuffin\Exceptions\DeleteMethodNotFoundException | Class was added. |
45-
| MINOR | src/Exceptions/DeletingFailedException.php#21 League\FactoryMuffin\Exceptions\DeletingFailedException | Class was added. |
46-
[... cut for brievity ...]
47-
+-------+-------------------------------------------------------------------------------------------------------------------+--------------------+
48-
49-
Function
50-
+-------+----------+--------+
51-
| Level | Location | Reason |
52-
+-------+----------+--------+
53-
```
36+
Class (MAJOR)
37+
+-------+-----------------------------------------+-----------------------+--------------------+------+
38+
| Level | Location | Target | Reason | Code |
39+
+-------+-----------------------------------------+-----------------------+--------------------+------+
40+
| MAJOR | tests\fixtures\before\ClassRemoved.php# | fixtures\ClassRemoved | Class was removed. | V005 |
41+
| MINOR | tests\fixtures\after\ClassAdded.php#5 | fixtures\ClassAdded | Class was added. | V014 |
42+
+-------+-----------------------------------------+-----------------------+--------------------+------+
43+
44+
Function (MAJOR)
45+
+-------+----------------------------------------------------------+-----------------------------------------------------------------------+----------------------------------+------+
46+
| Level | Location | Target | Reason | Code |
47+
+-------+----------------------------------------------------------+-----------------------------------------------------------------------+----------------------------------+------+
48+
| MAJOR | tests\fixtures\before\FunctionRemoved.php#5 | fixtures\functionRemoved::functionRemoved | Function has been removed. | V001 |
49+
| MAJOR | tests\fixtures\before\FunctionParameterMismatch.php#5 | fixtures\functionParameterMismatch::functionParameterMismatch | Function parameter changed. | V002 |
50+
| MINOR | tests\fixtures\after\FunctionAdded.php#5 | fixtures\functionAdded::functionAdded | Function has been added. | V003 |
51+
| PATCH | tests\fixtures\after\FunctionImplementationChanged.php#5 | fixtures\functionImplementationChanged::functionImplementationChanged | Function implementation changed. | V004 |
52+
+-------+----------------------------------------------------------+-----------------------------------------------------------------------+----------------------------------+------+
53+
54+
Interface (MAJOR)
55+
+-------+----------------------------------------------+---------------------------+------------------------+------+
56+
| Level | Location | Target | Reason | Code |
57+
+-------+----------------------------------------------+---------------------------+------------------------+------+
58+
| MAJOR | tests\fixtures\before\InterfaceRemoved.php#5 | fixtures\InterfaceRemoved | Interface was removed. | V033 |
59+
| MAJOR | tests\fixtures\after\InterfaceAdded.php#5 | fixtures\InterfaceAdded | Interface was added. | V032 |
60+
+-------+----------------------------------------------+---------------------------+------------------------+------+
5461

62+
Method (MAJOR)
63+
+-------+-------------------------------------------------------------+------------------------------------------------------+--------------------------------+------+
64+
| Level | Location | Target | Reason | Code |
65+
+-------+-------------------------------------------------------------+------------------------------------------------------+--------------------------------+------+
66+
| MAJOR | tests\fixtures\after\ClassMethodParameterChanged.php#7 | fixtures\ClassMethodParameterMismatch::newMethod | Method parameter changed. | V010 |
67+
| MAJOR | tests\fixtures\before\ClassMethodRemoved.php#7 | fixtures\ClassMethodRemoved::newMethod | Method has been removed. | V006 |
68+
| MAJOR | tests\fixtures\after\InterfaceMethodParameterMismatch.php#7 | fixtures\InterfaceMethodParameterMismatch::newMethod | Method parameter changed. | V036 |
69+
| MAJOR | tests\fixtures\before\InterfaceMethodRemoved.php#7 | fixtures\InterfaceMethodRemoved::newMethod | Method has been removed. | V035 |
70+
| MAJOR | tests\fixtures\after\TraitMethodParameterChanged.php#7 | fixtures\TraitMethodParameterMismatch::newMethod | Method parameter changed. | V042 |
71+
| MAJOR | tests\fixtures\before\TraitMethodRemoved.php#7 | fixtures\TraitMethodRemoved::newMethod | Method has been removed. | V038 |
72+
| MINOR | tests\fixtures\after\ClassMethodAdded.php#7 | fixtures\ClassMethodAdded::newMethod | Method has been added. | V015 |
73+
| MINOR | tests\fixtures\after\InterfaceMethodAdded.php#7 | fixtures\InterfaceMethodAdded::newMethod | Method has been added. | V034 |
74+
| MINOR | tests\fixtures\after\TraitAddedRemoved.php#7 | fixtures\TraitMethodAdded::newMethod | Method has been added. | V047 |
75+
| PATCH | tests\fixtures\after\ClassMethodImplementationChanged.php#7 | fixtures\ClassMethodImplementationChanged::newMethod | Method implementation changed. | V023 |
76+
| PATCH | tests\fixtures\after\ClassMethodParameterChanged.php#7 | fixtures\ClassMethodParameterMismatch::newMethod | Method parameter changed. | V010 |
77+
| PATCH | tests\fixtures\after\InterfaceMethodParameterMismatch.php#7 | fixtures\InterfaceMethodParameterMismatch::newMethod | Method parameter changed. | V036 |
78+
| PATCH | tests\fixtures\after\TraitMethodImplementationChanged.php#7 | fixtures\TraitMethodImplementationChanged::newMethod | Method implementation changed. | V038 |
79+
| PATCH | tests\fixtures\after\TraitMethodParameterChanged.php#7 | fixtures\TraitMethodParameterMismatch::newMethod | Method parameter changed. | V042 |
80+
+-------+-------------------------------------------------------------+------------------------------------------------------+--------------------------------+------+
81+
82+
Trait (MAJOR)
83+
+-------+------------------------------------------+-----------------------+--------------------+------+
84+
| Level | Location | Target | Reason | Code |
85+
+-------+------------------------------------------+-----------------------+--------------------+------+
86+
| MAJOR | tests\fixtures\before\TraitRemoved.php#5 | fixtures\TraitRemoved | Trait was removed. | V037 |
87+
| MINOR | tests\fixtures\after\TraitAdded.php#5 | fixtures\TraitAdded | Trait was added. | V046 |
88+
+-------+------------------------------------------+-----------------------+--------------------+------+
89+
90+
Time: 0.79 seconds, Memory: 4.28 MB
91+
```
92+
5593
## License
5694

57-
The code is licensed under the [MIT license](http://choosealicense.com/licenses/mit/). See license.txt.
95+
The code is licensed under the [MIT license](http://choosealicense.com/licenses/mit/). See license.txt.

docs/Ruleset.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
**Note** In *italic* are the rules that are not implemented yet. Feel free to submit a PR if you implement any of them.
2+
3+
# Functions
4+
5+
Code | Level | Rule
6+
-----|-------|-------
7+
V001 | MAJOR | Function removed
8+
V002 | MAJOR | Function parameter changed
9+
V003 | MINOR | Function added
10+
V004 | PATCH | Function implementation changed
11+
12+
# Classes
13+
14+
Code | Level | Rule
15+
-----|-------|-------
16+
V005 | MAJOR | Class removed
17+
V006 | MAJOR | Class public method removed
18+
V007 | MAJOR | *Class protected method removed*
19+
V008 | MAJOR | *Class public property removed*
20+
V009 | MAJOR | *Class protected property removed*
21+
V010 | MAJOR | Class public method parameter changed
22+
V011 | MAJOR | *Class protected method parameter changed*
23+
V012 | MAJOR | *New public constructor (does not match supertype)*
24+
V013 | MAJOR | *New protected constructor (does not match supertype)*
25+
V014 | MINOR | Class added
26+
V015 | MINOR | Class public method added *(display a notice that the method may overlap)* (MAJOR when not final)
27+
V016 | MINOR | *Class protected method added* *(display a notice that the method may overlap)* (MAJOR when not final)
28+
V017 | MINOR | *Final class public method added*
29+
V018 | MINOR | *Final class protected method added*
30+
V019 | MINOR | *Class public property added*
31+
V020 | MINOR | *Class protected property added*
32+
V021 | MINOR | Class protected method parameter changed (MAJOR when not final)
33+
V022 | MAJOR | Final class protected method removed
34+
V023 | PATCH | [Final] Class public class method implementation changed
35+
V024 | PATCH | [Final] Class *protected* class method implementation changed
36+
V025 | PATCH | [Final] Class *private* class method implementation changed
37+
V026 | PATCH | *Class private property added*
38+
V027 | PATCH | *Class private property removed*
39+
V028 | PATCH | *Class private method added*
40+
V029 | PATCH | *Class private method removed*
41+
V030 | PATCH | *Final class protected method added*
42+
V031 | PATCH | *Class private method parameter changed*
43+
44+
# Interface
45+
46+
Code | Level | Rule
47+
-----|-------|-------
48+
V032 | MAJOR | Interface added
49+
V033 | MAJOR | Interface removed
50+
V034 | MAJOR | Interface method added
51+
V035 | MAJOR | Interface method removed
52+
V036 | MAJOR | Interface method parameter changed
53+
54+
# Trait
55+
56+
Code | Level | Rule
57+
-----|-------|-------
58+
V037 | MAJOR | Trait removed
59+
V038 | MAJOR | Trait public method removed
60+
V039 | MAJOR | *Trait protected method removed*
61+
V040 | MAJOR | *Trait public property removed*
62+
V041 | MAJOR | *Trait protected property removed*
63+
V042 | MAJOR | Trait public method parameter changed
64+
V043 | MAJOR | *Trait protected method parameter changed*
65+
V044 | MAJOR | *New public constructor (does not match supertype)*
66+
V045 | MAJOR | *New protected constructor (does not match supertype)*
67+
V046 | MINOR | Trait added
68+
V047 | MINOR | Trait public method added *(display a notice that the method may overlap)* (MAJOR when not final)
69+
V048 | MINOR | *Trait protected method added* *(display a notice that the method may overlap)* (MAJOR when not final)*
70+
V049 | MINOR | *Trait public property added*
71+
V050 | MINOR | *Trait protected property added*
72+
V051 | MINOR | *Trait protected method parameter changed (MAJOR when not final)*
73+
V052 | PATCH | Trait public trait method implementation changed
74+
V053 | PATCH | *Trait *protected* trait method implementation changed*
75+
V054 | PATCH | *Trait *private* trait method implementation changed*
76+
V055 | PATCH | *Trait private property added*
77+
V056 | PATCH | *Trait private property removed*
78+
V057 | PATCH | *Trait private method added*
79+
V058 | PATCH | *Trait private method removed*
80+
V059 | PATCH | *Trait private method parameter changed*

src/PHPSemVerChecker/Console/Command/CompareCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Symfony\Component\Console\Helper\ProgressBar;
1111
use Symfony\Component\Console\Input\InputArgument;
1212
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Input\InputOption;
1314
use Symfony\Component\Console\Output\OutputInterface;
1415

1516
class CompareCommand extends Command {
@@ -21,6 +22,7 @@ protected function configure()
2122
->setDefinition([
2223
new InputArgument('source-before', InputArgument::REQUIRED, 'A directory to check'),
2324
new InputArgument('source-after', InputArgument::REQUIRED, 'A directory to check against'),
25+
new InputOption('full-path', null, InputOption::VALUE_NONE, 'Display the full path to the file instead of the relative path'),
2426
]);
2527
}
2628

@@ -56,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5658
$analyzer = new Analyzer();
5759
$report = $analyzer->analyze($registryBefore, $registryAfter);
5860

59-
$reporter = new Reporter($report);
61+
$reporter = new Reporter($report, $input);
6062
$reporter->output($output);
6163

6264
$duration = microtime(true) - $startTime;

src/PHPSemVerChecker/Operation/ClassAdded.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,15 @@ public function __construct($fileAfter, Class_ $classAfter)
3737
*/
3838
public function getLocation()
3939
{
40-
return $this->fileAfter . '#' . $this->classAfter->getLine();
40+
return $this->fileAfter;
41+
}
42+
43+
/**
44+
* @return int
45+
*/
46+
public function getLine()
47+
{
48+
return $this->classAfter->getLine();
4149
}
4250

4351
/**

src/PHPSemVerChecker/Operation/ClassMethodAdded.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ public function __construct($context, $fileAfter, Stmt $contextAfter, ClassMetho
5454
*/
5555
public function getLocation()
5656
{
57-
return $this->fileAfter . '#' . $this->classMethod->getLine();
57+
return $this->fileAfter;
58+
}
59+
60+
/**
61+
* @return int
62+
*/
63+
public function getLine()
64+
{
65+
return $this->classMethod->getLine();
5866
}
5967

6068
/**

src/PHPSemVerChecker/Operation/ClassMethodImplementationChanged.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ public function __construct($context, $fileBefore, \PhpParser\Node\Stmt $context
7171
*/
7272
public function getLocation()
7373
{
74-
return $this->fileAfter . '#' . $this->classMethodAfter->getLine();
74+
return $this->fileAfter;
75+
}
76+
77+
/**
78+
* @return int
79+
*/
80+
public function getLine()
81+
{
82+
return $this->classMethodAfter->getLine();
7583
}
7684

7785
/**

src/PHPSemVerChecker/Operation/ClassMethodOperation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PHPSemVerChecker\Operation;
44

5-
class ClassMethodOperation extends Operation
5+
abstract class ClassMethodOperation extends Operation
66
{
77
public function getCode()
88
{

src/PHPSemVerChecker/Operation/ClassMethodParameterChanged.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ public function __construct($context, $fileBefore, Stmt $contextBefore, ClassMet
7272
*/
7373
public function getLocation()
7474
{
75-
return $this->fileAfter . '#' . $this->classMethodAfter->getLine();
75+
return $this->fileAfter;
76+
}
77+
78+
/**
79+
* @return int
80+
*/
81+
public function getLine()
82+
{
83+
return $this->classMethodAfter->getLine();
7684
}
7785

7886
/**

src/PHPSemVerChecker/Operation/ClassMethodRemoved.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ public function __construct($context, $fileBefore, Stmt $contextBefore, ClassMet
5454
*/
5555
public function getLocation()
5656
{
57-
return $this->fileBefore . '#' . $this->classMethodBefore->getLine();
57+
return $this->fileBefore;
58+
}
59+
60+
/**
61+
* @return int
62+
*/
63+
public function getLine()
64+
{
65+
return $this->classMethodBefore->getLine();
5866
}
5967

6068
/**

src/PHPSemVerChecker/Operation/ClassRemoved.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ public function __construct($fileBefore, Class_ $classBefore)
3737
*/
3838
public function getLocation()
3939
{
40-
return $this->fileBefore . '#' . $this->classBefore->getLine();
40+
return $this->fileBefore;
41+
}
42+
43+
public function getLine()
44+
{
45+
$this->classBefore->getLine();
4146
}
4247

4348
/**

0 commit comments

Comments
 (0)