Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 794d47f

Browse files
authored
Merge pull request #26 from leanphp/code-style-guide
Add Code Style guides using PHP CodeSniffer
2 parents 803d56d + c601902 commit 794d47f

File tree

6 files changed

+65
-6
lines changed

6 files changed

+65
-6
lines changed

.appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,6 @@ install:
7777

7878
test_script:
7979
- cd c:\projects\phpspec-code-coverage
80-
- phpdbg -qrr vendor\phpspec\phpspec\bin\phpspec run -vvv
80+
- bin\phpcs
81+
- phpdbg -qrr vendor\phpspec\phpspec\bin\phpspec run --no-code-generation -vvv
8182

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ before_script:
1919
script:
2020
- composer validate
2121
- composer update
22+
- bin/phpcs
2223
- bin/phpspec run --no-code-generation
2324

2425
install:

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"phpunit/php-code-coverage": "~6.0"
3030
},
3131
"require-dev": {
32-
"bossa/phpspec2-expect": "^3.0"
32+
"bossa/phpspec2-expect": "^3.0",
33+
"escapestudios/symfony2-coding-standard": "^3.1",
34+
"squizlabs/php_codesniffer": "^3.2"
3335
},
3436
"suggest": {
3537
"ext-xdebug": "Install Xdebug to generate phpspec code coverage if you are not using phpdbg"

phpcs.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<!-- leanphp/common-dev phpcs.xml example config -->
3+
<ruleset name="LeanPHP Coding Standard">
4+
<description>LeanPHP Coding Standard</description>
5+
6+
<!-- directories and files to scan -->
7+
<file>src</file>
8+
9+
<!-- directories and files to exclude -->
10+
<exclude-pattern>test</exclude-pattern>
11+
<exclude-pattern>tests</exclude-pattern>
12+
<exclude-pattern>*Spec.php</exclude-pattern>
13+
14+
<!-- uncomment for a summary instead of detailed report -->
15+
<!--<arg name="report" value="summary"/>-->
16+
<arg value="p"/>>
17+
18+
<!-- Use Symfony2 Coding Standard -->
19+
<rule ref="vendor/escapestudios/symfony2-coding-standard/Symfony"/>
20+
</ruleset>

src/CodeCoverageExtension.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?php
2-
2+
/**
3+
* This file is part of the leanphp/phpspec-code-coverage package
4+
*
5+
* For the full copyright and license information, please see the LICENSE file
6+
* that was distributed with this source code.
7+
*
8+
* @license MIT
9+
*/
310
namespace LeanPHP\PhpSpec\CodeCoverage;
411

512
use LeanPHP\PhpSpec\CodeCoverage\Listener\CodeCoverageListener;
@@ -24,7 +31,7 @@ class CodeCoverageExtension implements \PhpSpec\Extension
2431
public function load(ServiceContainer $container, array $params = [])
2532
{
2633
foreach ($container->getByTag('console.commands') as $command) {
27-
if ($command->getName() == 'run') {
34+
if ($command->getName() === 'run') {
2835
$command->addOption('no-coverage', null, InputOption::VALUE_NONE, 'Skip code coverage generation');
2936
}
3037
}
@@ -48,7 +55,7 @@ public function load(ServiceContainer $container, array $params = [])
4855
}
4956

5057
if (isset($options['output'])) {
51-
if (!is_array($options['output']) && count($options['format']) == 1) {
58+
if (!is_array($options['output']) && count($options['format']) === 1) {
5259
$format = $options['format'][0];
5360
$options['output'] = array($format => $options['output']);
5461
}
@@ -100,6 +107,7 @@ public function load(ServiceContainer $container, array $params = [])
100107
}
101108

102109
$container->setParam('code_coverage', $options);
110+
103111
return $reports;
104112
});
105113

src/Listener/CodeCoverageListener.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?php
2-
2+
/**
3+
* This file is part of the leanphp/phpspec-code-coverage package
4+
*
5+
* For the full copyright and license information, please see the LICENSE file
6+
* that was distributed with this source code.
7+
*
8+
* @license MIT
9+
*/
310
namespace LeanPHP\PhpSpec\CodeCoverage\Listener;
411

512
use PhpSpec\Console\ConsoleIO;
@@ -20,6 +27,12 @@ class CodeCoverageListener implements EventSubscriberInterface
2027
private $options;
2128
private $enabled;
2229

30+
/**
31+
* @param ConsoleIO $io
32+
* @param CodeCoverage $coverage
33+
* @param [] $reports
34+
* @param boolean $skipCoverage
35+
*/
2336
public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $reports, $skipCoverage = false)
2437
{
2538
$this->io = $io;
@@ -40,6 +53,8 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
4053
/**
4154
* Note: We use array_map() instead of array_walk() because the latter expects
4255
* the callback to take the value as the first and the index as the seconds parameter.
56+
*
57+
* @param SuiteEvent $event
4358
*/
4459
public function beforeSuite(SuiteEvent $event)
4560
{
@@ -67,6 +82,9 @@ public function beforeSuite(SuiteEvent $event)
6782
);
6883
}
6984

85+
/**
86+
* @param ExampleEvent $event
87+
*/
7088
public function beforeExample(ExampleEvent $event)
7189
{
7290
if (!$this->enabled) {
@@ -83,6 +101,9 @@ public function beforeExample(ExampleEvent $event)
83101
$this->coverage->start($name);
84102
}
85103

104+
/**
105+
* @param ExampleEvent $event
106+
*/
86107
public function afterExample(ExampleEvent $event)
87108
{
88109
if (!$this->enabled) {
@@ -92,6 +113,9 @@ public function afterExample(ExampleEvent $event)
92113
$this->coverage->stop();
93114
}
94115

116+
/**
117+
* @param SuiteEvent $event
118+
*/
95119
public function afterSuite(SuiteEvent $event)
96120
{
97121
if (!$this->enabled) {
@@ -120,6 +144,9 @@ public function afterSuite(SuiteEvent $event)
120144
}
121145
}
122146

147+
/**
148+
* @param [] $options
149+
*/
123150
public function setOptions(array $options)
124151
{
125152
$this->options = $options + $this->options;

0 commit comments

Comments
 (0)