Skip to content

Commit 0de0ea4

Browse files
committed
Apply stricter coding standard (#435)
1 parent d4d1b7d commit 0de0ea4

File tree

300 files changed

+2169
-2097
lines changed

Some content is hidden

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

300 files changed

+2169
-2097
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.idea/
2+
/.phpcs-cache
23
/build/
34
/docs/_site/
45
/docs/Gemfile.lock

.styleci.yml

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1 @@
1-
preset: recommended
2-
3-
enabled:
4-
- concat_with_spaces
5-
- no_useless_else
6-
- strict
7-
8-
disabled:
9-
- concat_without_spaces
10-
- no_trailing_comma_in_list_call
11-
- phpdoc_summary
12-
- post_increment
13-
- self_accessor
14-
15-
finder:
16-
not-name:
17-
- ".phpstorm.meta.php"
18-
- "CommonMarkCoreExtension.php"
19-
- "FakeEmptyHtmlRenderer.php"
20-
- "InlinesOnlyExtension.php"
21-
- "SmartPunctExtension.php"
22-
- "TableExtension.php"
23-
not-path:
24-
- ".ripstech"
1+
preset: psr1

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
- name: phpstan
2727
php: 7.2
2828
env: 'PHPSTAN=true'
29+
- name: phpcs
30+
php: 7.2
31+
env: 'PHPCS=true'
2932
- name: rips
3033
php: 7.2
3134
env: 'RIPS=true'
@@ -59,6 +62,7 @@ install:
5962

6063
script:
6164
- if [[ $PHPSTAN ]]; then vendor/bin/phpstan analyse; fi
65+
- if [[ $PHPCS ]]; then vendor/bin/phpcs; fi
6266
- if [[ $PHPUNIT ]]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi
6367
- |
6468
if [[ $RIPS ]]; then

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"phpstan/phpstan": "^0.12",
3434
"phpunit/phpunit": "^8.5",
3535
"scrutinizer/ocular": "^1.5",
36-
"symfony/finder": "^4.2"
36+
"symfony/finder": "^4.2",
37+
"unleashedtech/php-coding-standard": "^2.1"
3738
},
3839
"conflict": {
3940
"scrutinizer/ocular": "1.7.*"

phpcs.xml.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<arg name="basepath" value="."/>
4+
<arg name="extensions" value="php"/>
5+
<arg name="parallel" value="80"/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
9+
<!-- Ignore warnings, show progress of the run and show sniff names -->
10+
<arg value="nps"/>
11+
12+
<!-- Directories to be checked -->
13+
<file>src</file>
14+
<file>tests/unit</file>
15+
<file>tests/functional</file>
16+
17+
<!-- Include full Unleashed Coding Standard -->
18+
<rule ref="Unleashed"/>
19+
</ruleset>

src/CommonMarkConverter.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* This file is part of the league/commonmark package.
57
*
@@ -46,10 +48,9 @@ class CommonMarkConverter implements MarkdownConverterInterface
4648
/**
4749
* Create a new commonmark converter instance.
4850
*
49-
* @param array<string, mixed> $config
50-
* @param EnvironmentInterface|null $environment
51+
* @param array<string, mixed> $config
5152
*/
52-
public function __construct(array $config = [], EnvironmentInterface $environment = null)
53+
public function __construct(array $config = [], ?EnvironmentInterface $environment = null)
5354
{
5455
if ($environment === null) {
5556
$environment = Environment::createCommonMarkEnvironment();
@@ -62,7 +63,7 @@ public function __construct(array $config = [], EnvironmentInterface $environmen
6263
$this->environment = $environment;
6364

6465
$this->markdownParser = new MarkdownParser($environment);
65-
$this->htmlRenderer = new HtmlRenderer($environment);
66+
$this->htmlRenderer = new HtmlRenderer($environment);
6667
}
6768

6869
public function getEnvironment(): EnvironmentInterface
@@ -73,13 +74,11 @@ public function getEnvironment(): EnvironmentInterface
7374
/**
7475
* Converts CommonMark to HTML.
7576
*
76-
* @param string $commonMark
77-
*
78-
* @throws \RuntimeException
77+
* @param string $commonMark The Markdown to convert
7978
*
80-
* @return string
79+
* @return string Rendered HTML
8180
*
82-
* @api
81+
* @throws \RuntimeException
8382
*/
8483
public function convertToHtml(string $commonMark): string
8584
{
@@ -93,11 +92,7 @@ public function convertToHtml(string $commonMark): string
9392
*
9493
* @see Converter::convertToHtml
9594
*
96-
* @param string $commonMark
97-
*
9895
* @throws \RuntimeException
99-
*
100-
* @return string
10196
*/
10297
public function __invoke(string $commonMark): string
10398
{

src/Configuration/Configuration.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* This file is part of the league/commonmark package.
57
*
@@ -27,16 +29,25 @@ public function __construct(array $config = [])
2729
$this->config = $config;
2830
}
2931

32+
/**
33+
* {@inheritdoc}
34+
*/
3035
public function merge(array $config = []): void
3136
{
3237
$this->config = \array_replace_recursive($this->config, $config);
3338
}
3439

40+
/**
41+
* {@inheritdoc}
42+
*/
3543
public function replace(array $config = []): void
3644
{
3745
$this->config = $config;
3846
}
3947

48+
/**
49+
* {@inheritdoc}
50+
*/
4051
public function get(?string $key = null, $default = null)
4152
{
4253
if ($key === null) {
@@ -48,13 +59,16 @@ public function get(?string $key = null, $default = null)
4859
return $this->getConfigByPath($key, $default);
4960
}
5061

51-
if (!isset($this->config[$key])) {
62+
if (! isset($this->config[$key])) {
5263
return $default;
5364
}
5465

5566
return $this->config[$key];
5667
}
5768

69+
/**
70+
* {@inheritdoc}
71+
*/
5872
public function set(string $key, $value = null): void
5973
{
6074
// accept a/b/c as ['a']['b']['c']
@@ -66,17 +80,16 @@ public function set(string $key, $value = null): void
6680
}
6781

6882
/**
69-
* @param string $keyPath
70-
* @param string|null $default
83+
* @param mixed|null $default
7184
*
7285
* @return mixed|null
7386
*/
7487
private function getConfigByPath(string $keyPath, $default = null)
7588
{
7689
$keyArr = \explode('/', $keyPath);
77-
$data = $this->config;
90+
$data = $this->config;
7891
foreach ($keyArr as $k) {
79-
if (!\is_array($data) || !isset($data[$k])) {
92+
if (! \is_array($data) || ! isset($data[$k])) {
8093
return $default;
8194
}
8295

@@ -87,19 +100,18 @@ private function getConfigByPath(string $keyPath, $default = null)
87100
}
88101

89102
/**
90-
* @param string $keyPath
91-
* @param string|null $value
103+
* @param mixed|null $value
92104
*/
93105
private function setByPath(string $keyPath, $value = null): void
94106
{
95-
$keyArr = \explode('/', $keyPath);
107+
$keyArr = \explode('/', $keyPath);
96108
$pointer = &$this->config;
97109
while (($k = \array_shift($keyArr)) !== null) {
98-
if (!\is_array($pointer)) {
110+
if (! \is_array($pointer)) {
99111
$pointer = [];
100112
}
101113

102-
if (!isset($pointer[$k])) {
114+
if (! isset($pointer[$k])) {
103115
$pointer[$k] = null;
104116
}
105117

src/Configuration/ConfigurationAwareInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* This file is part of the league/commonmark package.
57
*

src/Configuration/ConfigurationInterface.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* This file is part of the league/commonmark package.
57
*
@@ -17,17 +19,13 @@ interface ConfigurationInterface
1719
* Merge an existing array into the current configuration
1820
*
1921
* @param array<string, mixed> $config
20-
*
21-
* @return void
2222
*/
2323
public function merge(array $config = []): void;
2424

2525
/**
2626
* Replace the entire array with something else
2727
*
2828
* @param array<string, mixed> $config
29-
*
30-
* @return void
3129
*/
3230
public function replace(array $config = []): void;
3331

@@ -36,8 +34,7 @@ public function replace(array $config = []): void;
3634
*
3735
* The key can be a string or a slash-delimited path to a nested value
3836
*
39-
* @param string|null $key
40-
* @param mixed|null $default
37+
* @param mixed|null $default
4138
*
4239
* @return mixed|null
4340
*/
@@ -48,10 +45,7 @@ public function get(?string $key = null, $default = null);
4845
*
4946
* The key can be a string or a slash-delimited path to a nested value
5047
*
51-
* @param string $key
5248
* @param mixed|null $value
53-
*
54-
* @return void
5549
*/
5650
public function set(string $key, $value = null): void;
5751
}

src/Delimiter/Delimiter.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/*
46
* This file is part of the league/commonmark package.
57
*
@@ -48,24 +50,16 @@ final class Delimiter implements DelimiterInterface
4850
/** @var int|null */
4951
private $index;
5052

51-
/**
52-
* @param string $char
53-
* @param int $numDelims
54-
* @param AbstractStringContainer $node
55-
* @param bool $canOpen
56-
* @param bool $canClose
57-
* @param int|null $index
58-
*/
5953
public function __construct(string $char, int $numDelims, AbstractStringContainer $node, bool $canOpen, bool $canClose, ?int $index = null)
6054
{
61-
$this->char = $char;
62-
$this->length = $numDelims;
55+
$this->char = $char;
56+
$this->length = $numDelims;
6357
$this->originalLength = $numDelims;
64-
$this->inlineNode = $node;
65-
$this->canOpen = $canOpen;
66-
$this->canClose = $canClose;
67-
$this->active = true;
68-
$this->index = $index;
58+
$this->inlineNode = $node;
59+
$this->canOpen = $canOpen;
60+
$this->canClose = $canClose;
61+
$this->active = true;
62+
$this->index = $index;
6963
}
7064

7165
public function canClose(): bool

0 commit comments

Comments
 (0)