Skip to content

Commit ee8d556

Browse files
dplewisBenjamin Wilson Friedman
authored and
Benjamin Wilson Friedman
committed
Update PHP_CodeSniffer (#328)
* Add lint * update travis * coding style * add coverage to gitignore * removed ignore lines * nit
1 parent 20dd7a5 commit ee8d556

Some content is hidden

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

54 files changed

+705
-725
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ logs
88

99
# ignore test results
1010
phpunit-test-results
11+
12+
*.log
13+
14+
coverage.xml

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ php:
99
# - nightly
1010
before_install:
1111
- nvm install 6.11
12-
install:
12+
install:
1313
- composer install
1414
- npm install
1515
before_script:
1616
- npm start 1>&2
1717
- sleep 3
18+
- npm run lint
1819
script:
19-
- ./vendor/bin/phpunit --coverage-clover=coverage.xml
20+
- npm run test:coverage
2021

2122
after_success:
2223
- bash <(curl -s https://codecov.io/bash)

CONTRIBUTING.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To setup the Test Parse Server:
2727
* Run `npm install` from the project root to download the server and it's dependencies.
2828
* When you're ready to run tests use `npm start` from the project root to boot up the test server.
2929

30-
The embedded test server utilizes this [parse server test] project.
30+
The embedded test server utilizes this [parse server test] project.
3131
It's setup with the appropriate configuration to run the php sdk test suite.
3232
Additionally it handles setting up mongodb for the server.
3333

@@ -65,6 +65,18 @@ You should now be able to execute the tests, from project root folder:
6565

6666
./vendor/bin/phpunit
6767

68+
You may also run tests directly using phpunit as follows:
69+
70+
npm test
71+
72+
Make sure your code is linted with phpcs ([PSR-2 Coding Style]):
73+
74+
npm run lint
75+
76+
You can automatically fix lint errors with phpcbf:
77+
78+
npm run lint:fix
79+
6880
The test suite is setup for code coverage if you have [XDebug] installed and setup.
6981
Coverage is outputted as text and as html in the phpunit-test-results/ directory within the project root.
7082

@@ -79,3 +91,5 @@ If you have XDebug setup and can view code coverage please ensure that you do yo
7991
[XDebug]: https://xdebug.org/
8092
[parse server test]: https://github.com/montymxb/parse-server-test
8193
[Setup a local Parse Server instance]: https://github.com/parse-community/parse-server#user-content-locally
94+
[PSR-2 Coding Style]: http://www.php-fig.org/psr/psr-2/
95+

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "~4.0",
21-
"squizlabs/php_codesniffer": "~1.5",
21+
"squizlabs/php_codesniffer": "^3.0.1",
2222
"phpdocumentor/phpdocumentor": "~2.5"
2323
},
2424
"autoload": {

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"name": "parse-php-sdk",
33
"scripts": {
4-
"test": "echo \"Error: no test specified\" && exit 1",
4+
"test": "./vendor/bin/phpunit",
5+
"test:coverage": "./vendor/bin/phpunit --coverage-clover=coverage.xml",
6+
"lint": "./vendor/bin/phpcs --standard=./phpcs.xml.dist ./src/Parse ./tests/Parse",
7+
"lint:fix": "./vendor/bin/phpcbf --standard=./phpcs.xml.dist ./src/Parse ./tests/Parse",
58
"start" : "./node_modules/parse-server-test/run-server",
69
"stop" : "./node_modules/parse-server-test/stop-server"
710
},

phpcs.xml.dist

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="phpcsignore">
3+
<description>PHPCS Ignore Rule</description>
4+
<rule ref="PSR2" />
5+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
6+
<severity>0</severity>
7+
</rule>
8+
<rule ref="PSR2.Methods.MethodDeclaration">
9+
<severity>0</severity>
10+
</rule>
11+
<rule ref="PSR2.Classes.PropertyDeclaration.Underscore">
12+
<severity>0</severity>
13+
</rule>
14+
</ruleset>

src/Parse/HttpClients/ParseCurl.php

+9-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Parse\HttpClients;
99

10-
1110
use Parse\ParseException;
1211

1312
/**
@@ -27,11 +26,9 @@ class ParseCurl
2726
*/
2827
public function init()
2928
{
30-
if($this->curl === null) {
29+
if ($this->curl === null) {
3130
$this->curl = curl_init();
32-
3331
}
34-
3532
}
3633

3734
/**
@@ -42,9 +39,8 @@ public function init()
4239
*/
4340
public function exec()
4441
{
45-
if(!isset($this->curl)) {
42+
if (!isset($this->curl)) {
4643
throw new ParseException('You must call ParseCurl::init first');
47-
4844
}
4945

5046
return curl_exec($this->curl);
@@ -59,13 +55,11 @@ public function exec()
5955
*/
6056
public function setOption($option, $value)
6157
{
62-
if(!isset($this->curl)) {
58+
if (!isset($this->curl)) {
6359
throw new ParseException('You must call ParseCurl::init first');
64-
6560
}
6661

6762
curl_setopt($this->curl, $option, $value);
68-
6963
}
7064

7165
/**
@@ -76,13 +70,11 @@ public function setOption($option, $value)
7670
*/
7771
public function setOptionsArray($options)
7872
{
79-
if(!isset($this->curl)) {
73+
if (!isset($this->curl)) {
8074
throw new ParseException('You must call ParseCurl::init first');
81-
8275
}
8376

8477
curl_setopt_array($this->curl, $options);
85-
8678
}
8779

8880
/**
@@ -94,13 +86,11 @@ public function setOptionsArray($options)
9486
*/
9587
public function getInfo($info)
9688
{
97-
if(!isset($this->curl)) {
89+
if (!isset($this->curl)) {
9890
throw new ParseException('You must call ParseCurl::init first');
99-
10091
}
10192

10293
return curl_getinfo($this->curl, $info);
103-
10494
}
10595

10696
/**
@@ -111,13 +101,11 @@ public function getInfo($info)
111101
*/
112102
public function getError()
113103
{
114-
if(!isset($this->curl)) {
104+
if (!isset($this->curl)) {
115105
throw new ParseException('You must call ParseCurl::init first');
116-
117106
}
118107

119108
return curl_error($this->curl);
120-
121109
}
122110

123111
/**
@@ -128,31 +116,26 @@ public function getError()
128116
*/
129117
public function getErrorCode()
130118
{
131-
if(!isset($this->curl)) {
119+
if (!isset($this->curl)) {
132120
throw new ParseException('You must call ParseCurl::init first');
133-
134121
}
135122

136123
return curl_errno($this->curl);
137-
138124
}
139125

140126
/**
141127
* Closed our curl handle and disposes of it
142128
*/
143129
public function close()
144130
{
145-
if(!isset($this->curl)) {
131+
if (!isset($this->curl)) {
146132
throw new ParseException('You must call ParseCurl::init first');
147-
148133
}
149134

150135
// close our handle
151136
curl_close($this->curl);
152137

153138
// unset our curl handle
154139
$this->curl = null;
155-
156140
}
157-
158-
}
141+
}

0 commit comments

Comments
 (0)