Skip to content

Commit 63aadd1

Browse files
committed
Correct brace and parenthesis style
- `(arg)`, not `( arg )` - `if {`, not `if\n{`
1 parent e4d1a33 commit 63aadd1

File tree

8 files changed

+103
-131
lines changed

8 files changed

+103
-131
lines changed

composer/bin/test-reporter

+6-9
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,25 @@ $files = [
1010
__DIR__ . '/../../../../autoload.php',
1111
];
1212

13-
foreach ( $files as $file )
14-
{
15-
if ( file_exists( $file ) )
16-
{
13+
foreach ($files as $file) {
14+
if (file_exists($file)) {
1715
include_once $file;
1816

19-
define( 'PHP_TEST_REPORTER_COMPOSER_INSTALL', $file );
17+
define('PHP_TEST_REPORTER_COMPOSER_INSTALL', $file);
2018

2119
break;
2220
}
2321
}
2422

25-
if ( !defined( 'PHP_TEST_REPORTER_COMPOSER_INSTALL' ) )
26-
{
23+
if (!defined('PHP_TEST_REPORTER_COMPOSER_INSTALL')) {
2724
die(
2825
'You need to set up the project dependencies using the following commands:' . PHP_EOL .
2926
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
3027
'php composer.phar install' . PHP_EOL
3128
);
3229
}
3330

34-
$rootDir = realpath( dirname( PHP_TEST_REPORTER_COMPOSER_INSTALL ) . '/..' );
31+
$rootDir = realpath(dirname(PHP_TEST_REPORTER_COMPOSER_INSTALL) . '/..');
3532

36-
$app = new Application( $rootDir, 'Code Climate PHP Test Reporter', Version::VERSION );
33+
$app = new Application($rootDir, 'Code Climate PHP Test Reporter', Version::VERSION);
3734
$app->run();

src/Application.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class Application extends BaseApplication
2424
* @param string $name The name of the application
2525
* @param string $version The version of the application
2626
*/
27-
public function __construct( $rootDir, $name = 'UNKNOWN', $version = 'UNKNOWN' )
27+
public function __construct($rootDir, $name = 'UNKNOWN', $version = 'UNKNOWN')
2828
{
2929
$this->rootDir = $rootDir;
3030

31-
parent::__construct( $name, $version );
31+
parent::__construct($name, $version);
3232
}
3333

3434
// internal method
@@ -37,7 +37,7 @@ public function __construct( $rootDir, $name = 'UNKNOWN', $version = 'UNKNOWN' )
3737
* {@inheritdoc}
3838
* @see \Symfony\Component\Console\Application::getCommandName()
3939
*/
40-
protected function getCommandName( InputInterface $input )
40+
protected function getCommandName(InputInterface $input)
4141
{
4242
return 'test-reporter';
4343
}
@@ -63,7 +63,7 @@ protected function getDefaultCommands()
6363
protected function createTestReporterCommand()
6464
{
6565
$command = new TestReporterCommand();
66-
$command->setRootDir( $this->rootDir );
66+
$command->setRootDir($this->rootDir);
6767

6868
return $command;
6969
}

src/ConsoleCommands/TestReporterCommand.php

+14-18
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class TestReporterCommand extends Command
2727
protected function configure()
2828
{
2929
$this
30-
->setName( 'test-reporter' )
31-
->setDescription( 'Code Climate PHP Test Reporter' )
30+
->setName('test-reporter')
31+
->setDescription('Code Climate PHP Test Reporter')
3232
->addOption(
3333
'stdout',
3434
null,
@@ -48,34 +48,30 @@ protected function configure()
4848
* {@inheritdoc}
4949
* @see \Symfony\Component\Console\Command\Command::execute()
5050
*/
51-
protected function execute( InputInterface $input, OutputInterface $output )
51+
protected function execute(InputInterface $input, OutputInterface $output)
5252
{
5353
$ret = 0;
54-
$collector = new CoverageCollector( $input->getOption( 'coverage-report' ) );
54+
$collector = new CoverageCollector($input->getOption('coverage-report'));
5555
$json = $collector->collectAsJson();
5656

57-
if ( $input->getOption( 'stdout' ) )
58-
{
59-
$output->writeln( (string)$json );
60-
}
61-
else
62-
{
57+
if ($input->getOption('stdout')) {
58+
$output->writeln((string)$json);
59+
} else {
6360
$client = new ApiClient();
64-
$response = $client->send( $json );
65-
switch ( $response->code )
66-
{
61+
$response = $client->send($json);
62+
switch ($response->code) {
6763
case 200:
68-
$output->writeln( "Test coverage data sent." );
64+
$output->writeln("Test coverage data sent.");
6965
break;
7066

7167
case 401:
72-
$output->writeln( "Invalid CODECLIMATE_REPO_TOKEN." );
68+
$output->writeln("Invalid CODECLIMATE_REPO_TOKEN.");
7369
$ret = 1;
7470
break;
7571

7672
default:
77-
$output->writeln( "Unexpected response: " . $response->code . " " . $response->message );
78-
$output->writeln( $response->body );
73+
$output->writeln("Unexpected response: " . $response->code . " " . $response->message);
74+
$output->writeln($response->body);
7975
$ret = 1;
8076
break;
8177
}
@@ -93,7 +89,7 @@ protected function execute( InputInterface $input, OutputInterface $output )
9389
*
9490
* @return void
9591
*/
96-
public function setRootDir( $rootDir )
92+
public function setRootDir($rootDir)
9793
{
9894
$this->rootDir = $rootDir;
9995
}

src/TestReporter/ApiClient.php

+30-38
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ public function __construct()
1414
{
1515
$this->apiHost = "https://codeclimate.com";
1616

17-
if ( isset($_SERVER["CODECLIMATE_API_HOST"]) )
18-
{
17+
if (isset($_SERVER["CODECLIMATE_API_HOST"])) {
1918
$this->apiHost = $_SERVER["CODECLIMATE_API_HOST"];
2019
}
2120
}
@@ -27,7 +26,7 @@ public function __construct()
2726
*
2827
* @return \stdClass Response object with (code, message, headers & body properties)
2928
*/
30-
public function send( $json )
29+
public function send($json)
3130
{
3231
$response = new \stdClass;
3332
$payload = (string)$json;
@@ -38,29 +37,25 @@ public function send( $json )
3837
'Host: codeclimate.com',
3938
'Content-Type: application/json',
4039
'User-Agent: Code Climate (PHP Test Reporter v' . Version::VERSION . ')',
41-
'Content-Length: ' . strlen( $payload ),
40+
'Content-Length: ' . strlen($payload),
4241
],
4342
'content' => $payload,
4443
"timeout" => 10,
4544
],
4645
];
47-
$context = stream_context_create( $options );
46+
$context = stream_context_create($options);
4847
$url = $this->apiHost . '/test_reports';
4948

50-
if ( $stream = @fopen( $url, 'r', false, $context ) )
51-
{
52-
$meta = stream_get_meta_data( $stream );
53-
$rawResponse = implode( "\r\n", $meta['wrapper_data'] ) . "\r\n\r\n" . stream_get_contents( $stream );
54-
fclose( $stream );
49+
if ($stream = @fopen($url, 'r', false, $context)) {
50+
$meta = stream_get_meta_data($stream);
51+
$rawResponse = implode("\r\n", $meta['wrapper_data']) . "\r\n\r\n" . stream_get_contents($stream);
52+
fclose($stream);
5553

56-
if ( !empty($rawResponse) )
57-
{
58-
$response = $this->buildResponse( $response, $rawResponse );
54+
if (!empty($rawResponse)) {
55+
$response = $this->buildResponse($response, $rawResponse);
5956
}
60-
}
61-
else
62-
{
63-
$response = $this->sendWithCurl( $url, $payload );
57+
} else {
58+
$response = $this->sendWithCurl($url, $payload);
6459
}
6560

6661
return $response;
@@ -75,36 +70,33 @@ public function send( $json )
7570
*
7671
* @return \stdClass Response object with (code, message, headers & body properties)
7772
*/
78-
private function sendWithCurl( $url, $payload )
73+
private function sendWithCurl($url, $payload)
7974
{
8075
$response = new \stdClass;
81-
$curl = curl_init( $url );
82-
curl_setopt( $curl, CURLOPT_HEADER, true );
83-
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
84-
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 10 );
76+
$curl = curl_init($url);
77+
curl_setopt($curl, CURLOPT_HEADER, true);
78+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
79+
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
8580
curl_setopt(
8681
$curl,
8782
CURLOPT_HTTPHEADER,
8883
[
8984
'Host: codeclimate.com',
9085
'Content-Type: application/json',
9186
'User-Agent: Code Climate (PHP Test Reporter v' . Version::VERSION . ')',
92-
'Content-Length: ' . strlen( $payload ),
87+
'Content-Length: ' . strlen($payload),
9388
]
9489
);
95-
curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, 'POST' );
96-
curl_setopt( $curl, CURLOPT_POSTFIELDS, $payload );
97-
$rawResponse = curl_exec( $curl );
90+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
91+
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
92+
$rawResponse = curl_exec($curl);
9893

99-
$status = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
100-
if ( !empty($rawResponse) )
101-
{
102-
$response = $this->buildResponse( $response, $rawResponse );
103-
}
104-
else
105-
{
94+
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
95+
if (!empty($rawResponse)) {
96+
$response = $this->buildResponse($response, $rawResponse);
97+
} else {
10698
$error = error_get_last();
107-
preg_match( '/([0-9]{3})/', $error['message'], $match );
99+
preg_match('/([0-9]{3})/', $error['message'], $match);
108100
$errorCode = (isset($match[1])) ? $match[1] : ($status ? $status : 500);
109101

110102
$response->code = $errorCode;
@@ -124,11 +116,11 @@ private function sendWithCurl( $url, $payload )
124116
*
125117
* @return \stdClass Populated class object
126118
*/
127-
private function buildResponse( $response, $body )
119+
private function buildResponse($response, $body)
128120
{
129-
list($response->headers, $response->body) = explode( "\r\n\r\n", $body, 2 );
130-
$response->headers = explode( "\r\n", $response->headers );
131-
list(, $response->code, $response->message) = explode( ' ', $response->headers[0], 3 );
121+
list($response->headers, $response->body) = explode("\r\n\r\n", $body, 2);
122+
$response->headers = explode("\r\n", $response->headers);
123+
list(, $response->code, $response->message) = explode(' ', $response->headers[0], 3);
132124

133125
return $response;
134126
}

src/TestReporter/CoverageCollector.php

+13-18
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,29 @@ class CoverageCollector
1515
*/
1616
protected $cloverPaths = [ ];
1717

18-
public function __construct( $paths )
18+
public function __construct($paths)
1919
{
2020
$rootDir = getcwd();
2121
$config = new Configuration();
22-
$config->setRootDir( $rootDir );
23-
$this->setCloverPaths( $paths );
24-
foreach ( $this->getCloverPaths() as $path )
25-
{
26-
if ( file_exists( $path ) )
27-
{
28-
$config->addCloverXmlPath( $path );
29-
}
30-
else
31-
{
32-
$config->addCloverXmlPath( $rootDir . DIRECTORY_SEPARATOR . $path );
22+
$config->setRootDir($rootDir);
23+
$this->setCloverPaths($paths);
24+
foreach ($this->getCloverPaths() as $path) {
25+
if (file_exists($path)) {
26+
$config->addCloverXmlPath($path);
27+
} else {
28+
$config->addCloverXmlPath($rootDir . DIRECTORY_SEPARATOR . $path);
3329
}
3430
}
3531

36-
$this->api = new Jobs( $config );
32+
$this->api = new Jobs($config);
3733
}
3834

3935
/**
4036
* Set a list of Clover XML paths
4137
*
4238
* @param array $paths Array of relative paths to Clovers XML files
4339
*/
44-
public function setCloverPaths( $paths )
40+
public function setCloverPaths($paths)
4541
{
4642
$this->cloverPaths = $paths;
4743
}
@@ -60,11 +56,10 @@ public function collectAsJson()
6056
$cloverJsonFile = $this->api->collectCloverXml()->getJsonFile();
6157

6258
$jsonFile = new JsonFile();
63-
$jsonFile->setRunAt( $cloverJsonFile->getRunAt() );
59+
$jsonFile->setRunAt($cloverJsonFile->getRunAt());
6460

65-
foreach ( $cloverJsonFile->getSourceFiles() as $sourceFile )
66-
{
67-
$jsonFile->addSourceFile( $sourceFile );
61+
foreach ($cloverJsonFile->getSourceFiles() as $sourceFile) {
62+
$jsonFile->addSourceFile($sourceFile);
6863
}
6964

7065
return $jsonFile;

src/TestReporter/Entity/CiInfo.php

+8-16
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,35 @@ class CiInfo
55
{
66
public function toArray()
77
{
8-
if ( isset($_SERVER["TRAVIS"]) )
9-
{
8+
if (isset($_SERVER["TRAVIS"])) {
109
return $this->travisProperties();
1110
}
1211

13-
if ( isset($_SERVER["CIRCLECI"]) )
14-
{
12+
if (isset($_SERVER["CIRCLECI"])) {
1513
return $this->circleProperties();
1614
}
1715

18-
if ( isset($_SERVER["SEMAPHORE"]) )
19-
{
16+
if (isset($_SERVER["SEMAPHORE"])) {
2017
return $this->semaphoreProperties();
2118
}
2219

23-
if ( isset($_SERVER["JENKINS_URL"]) )
24-
{
20+
if (isset($_SERVER["JENKINS_URL"])) {
2521
return $this->jenkinsProperties();
2622
}
2723

28-
if ( isset($_SERVER["TDDIUM"]) )
29-
{
24+
if (isset($_SERVER["TDDIUM"])) {
3025
return $this->tddiumProperties();
3126
}
3227

33-
if ( isset($_SERVER["CI_NAME"]) && preg_match( '/codeship/i', $_SERVER["CI_NAME"] ) )
34-
{
28+
if (isset($_SERVER["CI_NAME"]) && preg_match('/codeship/i', $_SERVER["CI_NAME"])) {
3529
return $this->codeshipProperties();
3630
}
3731

38-
if ( isset($_SERVER["BUILDKITE"]) )
39-
{
32+
if (isset($_SERVER["BUILDKITE"])) {
4033
return $this->buildkiteProperties();
4134
}
4235

43-
if ( isset($_SERVER["WERCKER"]) )
44-
{
36+
if (isset($_SERVER["WERCKER"])) {
4537
return $this->werckerProperties();
4638
}
4739

0 commit comments

Comments
 (0)