Skip to content

Commit 28a9828

Browse files
committed
Update code standards to PSR12.
1 parent 60d1952 commit 28a9828

36 files changed

+176
-70
lines changed

build.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
exit(1);
99
}
1010

11-
$phpcs = './vendor/bin/phpcs --standard=' . __DIR__ . '/vendor/traderinteractive/coding-standard/DWS -n';
12-
$phpcs .= ' src tests *.php';
13-
passthru($phpcs, $returnStatus);
11+
passthru('./vendor/bin/phpcs -n', $returnStatus);
1412
if ($returnStatus !== 0) {
1513
exit(1);
1614
}

phpcs.xml.dist

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PHP_CodeSniffer">
3+
<config name="ignore_warnings_on_exit" value="true"/>
4+
<file>tests</file>
5+
<file>src</file>
6+
<file>build.php</file>
7+
<arg name="report" value="full"/>
8+
<arg name="colors" />
9+
<arg value="p" />
10+
<rule ref="PSR12">
11+
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
12+
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
13+
</rule>
14+
</ruleset>

src/Application.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes;
34

45
use Symfony\Component\Console\Application as SymfonyApplication;

src/BuildRelease.php

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes;
34

45
use Gregwar\Cache\Cache;
@@ -97,7 +98,13 @@ protected function configure()
9798
null,
9899
InputOption::VALUE_NONE,
99100
'Only include Pull Requests in the change list.'
100-
)->addOption('cache-dir', null, InputOption::VALUE_REQUIRED, 'The access token cache location', dirname(__DIR__))->addOption(
101+
)->addOption(
102+
'cache-dir',
103+
null,
104+
InputOption::VALUE_REQUIRED,
105+
'The access token cache location',
106+
dirname(__DIR__)
107+
)->addOption(
101108
'token-file',
102109
null,
103110
InputOption::VALUE_REQUIRED,
@@ -127,7 +134,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
127134
$this->versionFactory = new CalendarVersionFactory();
128135
}
129136

130-
$promptFactory = new PromptFactory($input, $output, $this->getHelperSet()->get('question'), $this->getHelperSet()->get('formatter'));
137+
$promptFactory = new PromptFactory(
138+
$input,
139+
$output,
140+
$this->getHelperSet()->get('question'),
141+
$this->getHelperSet()->get('formatter')
142+
);
131143

132144
$client = GithubClient::createWithToken(
133145
$this->_getToken($input, $promptFactory),
@@ -157,7 +169,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
157169

158170
$done = false;
159171
while (!$done) {
160-
$choice = $promptFactory->invoke('What would you like to do?', $defaultChoice, $choices, $release->previewFormat());
172+
$choice = $promptFactory->invoke(
173+
'What would you like to do?',
174+
$defaultChoice,
175+
$choices,
176+
$release->previewFormat()
177+
);
161178
$result = $this->_handleUserInput($release, $promptFactory, $client, $input, $output, $choice);
162179
if ($result === true) {
163180
$done = true;
@@ -189,8 +206,7 @@ private function _handleUserInput(
189206
InputInterface $input,
190207
OutputInterface $output,
191208
string $choice
192-
)
193-
{
209+
) {
194210
$typeManager = $this->typeManager;
195211
$targetBranch = $baseTagName = null;
196212
switch ($choice) {
@@ -205,7 +221,7 @@ private function _handleUserInput(
205221
return $this->_buildRelease($input, $output, $client, $targetBranch, $baseTagName);
206222
break;
207223
case 'c':
208-
$selectTypeForChange = function(Change $change) use($promptFactory, $typeManager) {
224+
$selectTypeForChange = function (Change $change) use ($promptFactory, $typeManager) {
209225
$choice = $promptFactory->invoke(
210226
'What type of change is this PR?',
211227
$change->getType()->getCode(),
@@ -229,7 +245,13 @@ private function _handleUserInput(
229245
$currentVersion = $release->currentVersion;
230246
$defaultVersion = $release->version;
231247
$release->version = $this->versionFactory->createVersion(
232-
$promptFactory->invoke("Version Number (current: {$currentVersion})", $defaultVersion, $suggestedVersions, null, false)
248+
$promptFactory->invoke(
249+
"Version Number (current: {$currentVersion})",
250+
$defaultVersion,
251+
$suggestedVersions,
252+
null,
253+
false
254+
)
233255
);
234256
break;
235257
case 'n':
@@ -267,8 +289,13 @@ private function _handleUserInput(
267289
*
268290
* @throws \Exception if tag already exists
269291
*/
270-
private function _buildRelease(InputInterface $input, OutputInterface $output, GithubClient $client, $targetBranch, $baseTagName)
271-
{
292+
private function _buildRelease(
293+
InputInterface $input,
294+
OutputInterface $output,
295+
GithubClient $client,
296+
$targetBranch,
297+
$baseTagName
298+
) {
272299
$currentVersion = $this->versionFactory->createVersion($baseTagName);
273300

274301
$typeSelector = null;
@@ -294,7 +321,15 @@ private function _buildRelease(InputInterface $input, OutputInterface $output, G
294321
$releaseName = $this->_getReleaseName($input);
295322
$isDraft = !$input->getOption('publish');
296323

297-
return new Release($changes, $currentVersion, $newVersion, $releaseName, $releaseNotes, $targetBranch, $isDraft);
324+
return new Release(
325+
$changes,
326+
$currentVersion,
327+
$newVersion,
328+
$releaseName,
329+
$releaseNotes,
330+
$targetBranch,
331+
$isDraft
332+
);
298333
}
299334

300335
private function _getChangesInRange(
@@ -303,8 +338,7 @@ private function _getChangesInRange(
303338
$startCommitish,
304339
$endCommitish,
305340
callable $changePrompter = null
306-
)
307-
{
341+
) {
308342
$commitDepth = 1;
309343
$argument = (int)$input->getOption('commit-depth');
310344
if ($argument >= 1) {
@@ -313,7 +347,10 @@ private function _getChangesInRange(
313347

314348
$commitGraph = new GithubCommitGraph($client->getCommitsInRange($startCommitish, $endCommitish));
315349
$leadingCommits = $commitGraph->firstParents($commitDepth);
316-
$changeListFactory = new ChangeListFactory(new ChangeFactory($this->typeManager, $changePrompter), $this->typeManager);
350+
$changeListFactory = new ChangeListFactory(
351+
new ChangeFactory($this->typeManager, $changePrompter),
352+
$this->typeManager
353+
);
317354

318355
return $changeListFactory->createFromCommits($leadingCommits);
319356
}
@@ -334,7 +371,13 @@ private function _getToken(InputInterface $input, PromptFactory $promptFactory)
334371

335372
$cache = new Cache($input->getOption('cache-dir'));
336373

337-
return trim($cache->getOrCreate($input->getOption('token-file'), [], $promptFactory->create('Please enter a github access token')));
374+
return trim(
375+
$cache->getOrCreate(
376+
$input->getOption('token-file'),
377+
[],
378+
$promptFactory->create('Please enter a github access token')
379+
)
380+
);
338381
}
339382

340383
/**
@@ -457,8 +500,7 @@ private function _submitRelease(
457500
PromptFactory $promptFactory,
458501
GithubClient $client,
459502
Release $release
460-
)
461-
{
503+
) {
462504
$defaultResponse = !$input->getOption('dry-run');
463505
$output->writeln($release->previewFormat());
464506
if ($promptFactory->invoke('Are you sure?', $defaultResponse)) {

src/CalendarVersion.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes;
34

45
use Herrera\Version\Parser as VersionParser;

src/CalendarVersionFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes;
34

45
final class CalendarVersionFactory implements VersionFactoryInterface
@@ -10,7 +11,7 @@ final class CalendarVersionFactory implements VersionFactoryInterface
1011
*
1112
* @return VersionInterface new version object
1213
*/
13-
public function createVersion($version = null) : VersionInterface
14+
public function createVersion($version = null): VersionInterface
1415
{
1516
return new CalendarVersion($version);
1617
}

src/Change/Change.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes\Change;
34

45
use Guywithnose\ReleaseNotes\Type\Type;
56

67
class Change implements ChangeInterface
78
{
8-
const TYPE_IGNORE = 'x';
9+
public const TYPE_IGNORE = 'x';
910

1011
/** @type Type The type of the change. */
1112
protected $_type;
@@ -45,7 +46,7 @@ public function setType(Type $type)
4546
*
4647
* @return Type The type code.
4748
*/
48-
public function getType() : Type
49+
public function getType(): Type
4950
{
5051
return $this->_type;
5152
}
@@ -67,7 +68,7 @@ public function setLink(string $link)
6768
*
6869
* @return string The link.
6970
*/
70-
public function getLink() : string
71+
public function getLink(): string
7172
{
7273
return $this->_link;
7374
}
@@ -87,7 +88,7 @@ public function displayType()
8788
*
8889
* @return string A short representation of the change.
8990
*/
90-
public function displayShort() : string
91+
public function displayShort(): string
9192
{
9293
if (!empty($this->getLink())) {
9394
return '* [' . strtok($this->_message, "\n") . "]({$this->getLink()})";
@@ -101,7 +102,7 @@ public function displayShort() : string
101102
*
102103
* @return string A long representation of the change.
103104
*/
104-
public function displayFull() : string
105+
public function displayFull(): string
105106
{
106107
return $this->_message;
107108
}

src/Change/ChangeFactory.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes\Change;
34

45
use Guywithnose\ReleaseNotes\Type\TypeManager;
@@ -14,15 +15,15 @@ class ChangeFactory
1415
/**
1516
* Initialize the change factory with the type selector.
1617
*
17-
* The type selector is a function that is passed the change and must return a valid type (@see \Guywithnose\ReleaseNotes\Change::types) or
18-
* null to use the default type.
18+
* The type selector is a function that is passed the change and must return a valid type
19+
* (@see \Guywithnose\ReleaseNotes\Change::types) or null to use the default type.
1920
*
2021
* @param callable $typeSelector The type selector function.
2122
*/
2223
public function __construct(TypeManager $typeManager, callable $typeSelector = null)
2324
{
2425
$this->typeManager = $typeManager;
25-
$this->_typeSelector = $typeSelector ?: function(Change $change) {
26+
$this->_typeSelector = $typeSelector ?: function (Change $change) {
2627
return $change->getType();
2728
};
2829
}
@@ -38,11 +39,14 @@ public function createFromCommit(array $commit)
3839
$typeSelector = $this->_typeSelector;
3940
$change = null;
4041

42+
$mergePRRegexp = '/Merge pull request #([0-9]*)[^\n]*\n[^\n]*\n(.*)/s';
43+
$mergeBranchRegExp = '/Merge branch \'([^\']*)\'[^\n]*\n[^\n]*\n(.*)/s';
44+
4145
if (count($commit['parents']) > 1) {
4246
$change = null;
43-
if (preg_match('/Merge pull request #([0-9]*)[^\n]*\n[^\n]*\n(.*)/s', $commit['commit']['message'], $matches)) {
47+
if (preg_match($mergePRRegexp, $commit['commit']['message'], $matches)) {
4448
$change = new PullRequest((int)$matches[1], $matches[2], $this->typeManager->getDefaultType());
45-
} elseif (preg_match('/Merge branch \'([^\']*)\'[^\n]*\n[^\n]*\n(.*)/s', $commit['commit']['message'], $matches)) {
49+
} elseif (preg_match($mergeBranchRegExp, $commit['commit']['message'], $matches)) {
4650
$change = new Merge($matches[1], $matches[2], $this->typeManager->getDefaultType());
4751
} else {
4852
$change = new Change($commit['commit']['message'], $this->typeManager->getDefaultType());

src/Change/ChangeInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes\Change;
34

45
use Guywithnose\ReleaseNotes\Type\Type;
@@ -19,7 +20,7 @@ public function setType(Type $type);
1920
*
2021
* @return Type The type code.
2122
*/
22-
public function getType() : Type;
23+
public function getType(): Type;
2324

2425
/**
2526
* Sets the link.
@@ -35,19 +36,19 @@ public function setLink(string $link);
3536
*
3637
* @return string The link.
3738
*/
38-
public function getLink() : string;
39+
public function getLink(): string;
3940

4041
/**
4142
* Returns a short markdown snippet of the change for use in release notes.
4243
*
4344
* @return string A short representation of the change.
4445
*/
45-
public function displayShort() : string;
46+
public function displayShort(): string;
4647

4748
/**
4849
* Returns a long markdown version of the change for use in user display.
4950
*
5051
* @return string A long representation of the change.
5152
*/
52-
public function displayFull() : string;
53+
public function displayFull(): string;
5354
}

src/Change/ChangeList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes\Change;
34

45
use Guywithnose\ReleaseNotes\Type\Type;

src/Change/ChangeListFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes\Change;
34

45
use Guywithnose\ReleaseNotes\Type\TypeManager;

src/Change/Merge.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Guywithnose\ReleaseNotes\Change;
34

45
use Guywithnose\ReleaseNotes\Type\Type;
@@ -27,7 +28,7 @@ public function __construct($branch, $message, Type $type)
2728
*
2829
* @return string A short representation of the merge.
2930
*/
30-
public function displayShort() : string
31+
public function displayShort(): string
3132
{
3233
return parent::displayShort() . "&nbsp;<sup>[{$this->_branch}]</sup>";
3334
}
@@ -37,7 +38,7 @@ public function displayShort() : string
3738
*
3839
* @return string A long representation of the merge.
3940
*/
40-
public function displayFull() : string
41+
public function displayFull(): string
4142
{
4243
return "### {$this->_branch}\n{$this->_message}";
4344
}

0 commit comments

Comments
 (0)