Skip to content

Commit

Permalink
Apply stricter coding standard (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed May 9, 2020
1 parent d4d1b7d commit 6ac414f
Show file tree
Hide file tree
Showing 300 changed files with 2,154 additions and 2,081 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea/
/.phpcs-cache
/build/
/docs/_site/
/docs/Gemfile.lock
Expand Down
24 changes: 0 additions & 24 deletions .styleci.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: phpstan
php: 7.2
env: 'PHPSTAN=true'
- name: phpcs
php: 7.2
env: 'PHPCS=true'
- name: rips
php: 7.2
env: 'RIPS=true'
Expand Down Expand Up @@ -59,6 +62,7 @@ install:

script:
- if [[ $PHPSTAN ]]; then vendor/bin/phpstan analyse; fi
- if [[ $PHPCS ]]; then vendor/bin/phpcs; fi
- if [[ $PHPUNIT ]]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi
- |
if [[ $RIPS ]]; then
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^8.5",
"scrutinizer/ocular": "^1.5",
"symfony/finder": "^4.2"
"symfony/finder": "^4.2",
"unleashedtech/php-coding-standard": "^2.1"
},
"conflict": {
"scrutinizer/ocular": "1.7.*"
Expand Down
19 changes: 19 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>

<!-- Directories to be checked -->
<file>src</file>
<file>tests/unit</file>
<file>tests/functional</file>

<!-- Include full Unleashed Coding Standard -->
<rule ref="Unleashed"/>
</ruleset>
21 changes: 8 additions & 13 deletions src/CommonMarkConverter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the league/commonmark package.
*
Expand Down Expand Up @@ -46,10 +48,9 @@ class CommonMarkConverter implements MarkdownConverterInterface
/**
* Create a new commonmark converter instance.
*
* @param array<string, mixed> $config
* @param EnvironmentInterface|null $environment
* @param array<string, mixed> $config
*/
public function __construct(array $config = [], EnvironmentInterface $environment = null)
public function __construct(array $config = [], ?EnvironmentInterface $environment = null)
{
if ($environment === null) {
$environment = Environment::createCommonMarkEnvironment();
Expand All @@ -62,7 +63,7 @@ public function __construct(array $config = [], EnvironmentInterface $environmen
$this->environment = $environment;

$this->markdownParser = new MarkdownParser($environment);
$this->htmlRenderer = new HtmlRenderer($environment);
$this->htmlRenderer = new HtmlRenderer($environment);
}

public function getEnvironment(): EnvironmentInterface
Expand All @@ -73,13 +74,11 @@ public function getEnvironment(): EnvironmentInterface
/**
* Converts CommonMark to HTML.
*
* @param string $commonMark
*
* @throws \RuntimeException
* @param string $commonMark The Markdown to convert
*
* @return string
* @return string Rendered HTML
*
* @api
* @throws \RuntimeException
*/
public function convertToHtml(string $commonMark): string
{
Expand All @@ -93,11 +92,7 @@ public function convertToHtml(string $commonMark): string
*
* @see Converter::convertToHtml
*
* @param string $commonMark
*
* @throws \RuntimeException
*
* @return string
*/
public function __invoke(string $commonMark): string
{
Expand Down
32 changes: 22 additions & 10 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the league/commonmark package.
*
Expand Down Expand Up @@ -27,16 +29,25 @@ public function __construct(array $config = [])
$this->config = $config;
}

/**
* {@inheritdoc}
*/
public function merge(array $config = []): void
{
$this->config = \array_replace_recursive($this->config, $config);
}

/**
* {@inheritdoc}
*/
public function replace(array $config = []): void
{
$this->config = $config;
}

/**
* {@inheritdoc}
*/
public function get(?string $key = null, $default = null)
{
if ($key === null) {
Expand All @@ -48,13 +59,16 @@ public function get(?string $key = null, $default = null)
return $this->getConfigByPath($key, $default);
}

if (!isset($this->config[$key])) {
if (! isset($this->config[$key])) {
return $default;
}

return $this->config[$key];
}

/**
* {@inheritdoc}
*/
public function set(string $key, $value = null): void
{
// accept a/b/c as ['a']['b']['c']
Expand All @@ -66,17 +80,16 @@ public function set(string $key, $value = null): void
}

/**
* @param string $keyPath
* @param string|null $default
* @param mixed|null $default
*
* @return mixed|null
*/
private function getConfigByPath(string $keyPath, $default = null)
{
$keyArr = \explode('/', $keyPath);
$data = $this->config;
$data = $this->config;
foreach ($keyArr as $k) {
if (!\is_array($data) || !isset($data[$k])) {
if (! \is_array($data) || ! isset($data[$k])) {
return $default;
}

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

/**
* @param string $keyPath
* @param string|null $value
* @param mixed|null $value
*/
private function setByPath(string $keyPath, $value = null): void
{
$keyArr = \explode('/', $keyPath);
$keyArr = \explode('/', $keyPath);
$pointer = &$this->config;
while (($k = \array_shift($keyArr)) !== null) {
if (!\is_array($pointer)) {
if (! \is_array($pointer)) {
$pointer = [];
}

if (!isset($pointer[$k])) {
if (! isset($pointer[$k])) {
$pointer[$k] = null;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Configuration/ConfigurationAwareInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the league/commonmark package.
*
Expand Down
12 changes: 3 additions & 9 deletions src/Configuration/ConfigurationInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the league/commonmark package.
*
Expand All @@ -17,17 +19,13 @@ interface ConfigurationInterface
* Merge an existing array into the current configuration
*
* @param array<string, mixed> $config
*
* @return void
*/
public function merge(array $config = []): void;

/**
* Replace the entire array with something else
*
* @param array<string, mixed> $config
*
* @return void
*/
public function replace(array $config = []): void;

Expand All @@ -36,8 +34,7 @@ public function replace(array $config = []): void;
*
* The key can be a string or a slash-delimited path to a nested value
*
* @param string|null $key
* @param mixed|null $default
* @param mixed|null $default
*
* @return mixed|null
*/
Expand All @@ -48,10 +45,7 @@ public function get(?string $key = null, $default = null);
*
* The key can be a string or a slash-delimited path to a nested value
*
* @param string $key
* @param mixed|null $value
*
* @return void
*/
public function set(string $key, $value = null): void;
}
24 changes: 9 additions & 15 deletions src/Delimiter/Delimiter.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the league/commonmark package.
*
Expand Down Expand Up @@ -48,24 +50,16 @@ final class Delimiter implements DelimiterInterface
/** @var int|null */
private $index;

/**
* @param string $char
* @param int $numDelims
* @param AbstractStringContainer $node
* @param bool $canOpen
* @param bool $canClose
* @param int|null $index
*/
public function __construct(string $char, int $numDelims, AbstractStringContainer $node, bool $canOpen, bool $canClose, ?int $index = null)
{
$this->char = $char;
$this->length = $numDelims;
$this->char = $char;
$this->length = $numDelims;
$this->originalLength = $numDelims;
$this->inlineNode = $node;
$this->canOpen = $canOpen;
$this->canClose = $canClose;
$this->active = true;
$this->index = $index;
$this->inlineNode = $node;
$this->canOpen = $canOpen;
$this->canClose = $canClose;
$this->active = true;
$this->index = $index;
}

public function canClose(): bool
Expand Down
2 changes: 2 additions & 0 deletions src/Delimiter/DelimiterInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the league/commonmark package.
*
Expand Down

0 comments on commit 6ac414f

Please sign in to comment.