Skip to content

Commit

Permalink
feat(php7): run the code standard fixer with PHP7 standards
Browse files Browse the repository at this point in the history
  • Loading branch information
e-picas committed Jan 25, 2024
1 parent faf8844 commit 5a34609
Show file tree
Hide file tree
Showing 82 changed files with 1,668 additions and 1,524 deletions.
9 changes: 4 additions & 5 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
*
*/

$finder = Symfony\CS\Finder\DefaultFinder::create();
$finder
$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->name('*.php')
->name('markdown-extended')
->name('mde-dev')
;

$config = Symfony\CS\Config\Config::create();
$config = new PhpCsFixer\Config();
$config
->setUsingCache(false)
->fixers([
->setRules([
'@PHP74Migration' => true,
'@PSR12' => true,
])
->finder($finder)
->setFinder($finder)
;

return $config;
12 changes: 7 additions & 5 deletions bin/markdown-extended
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ if (strpos(PHP_SAPI, 'cli') === false) {
// get a well-formatted path
$bootstrapGetPath = function ($parts) {
return implode(DIRECTORY_SEPARATOR, array_map(
function ($p) { return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $p); },
is_array($parts) ? $parts : array($parts)
function ($p) {
return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $p);
},
is_array($parts) ? $parts : [$parts]
));
};

// namespaces loader
if (file_exists($bootstrapper = $bootstrapGetPath(array(
dirname(__DIR__), 'src', 'bootstrap.php'
)))) {
if (file_exists($bootstrapper = $bootstrapGetPath([
dirname(__DIR__), 'src', 'bootstrap.php',
]))) {
require_once $bootstrapper;
} else {
trigger_error(
Expand Down
12 changes: 7 additions & 5 deletions bin/mde-dev
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ if (strpos(PHP_SAPI, 'cli') === false) {
// get a well-formatted path
$bootstrapGetPath = function ($parts) {
return implode(DIRECTORY_SEPARATOR, array_map(
function ($p) { return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $p); },
is_array($parts) ? $parts : array($parts)
function ($p) {
return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $p);
},
is_array($parts) ? $parts : [$parts]
));
};

// namespaces loader
if (file_exists($bootstrapper = $bootstrapGetPath(array(
dirname(__DIR__), 'src', 'bootstrap.php'
)))) {
if (file_exists($bootstrapper = $bootstrapGetPath([
dirname(__DIR__), 'src', 'bootstrap.php',
]))) {
require_once $bootstrapper;
} else {
trigger_error(
Expand Down
69 changes: 37 additions & 32 deletions src/MarkdownExtended/API/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,71 @@

namespace MarkdownExtended\API;

use \MarkdownExtended\Exception\UnexpectedValueException;
use \MarkdownExtended\Util\Helper;
use \MarkdownExtended\Util\Registry;
use MarkdownExtended\Exception\UnexpectedValueException;
use MarkdownExtended\Util\Helper;
use MarkdownExtended\Util\Registry;

class Kernel
{
/**
* Identify an OutputFormat object
*/
const TYPE_OUTPUTFORMAT = 'output_format';
public const TYPE_OUTPUTFORMAT = 'output_format';

/**
* Identify a Gamut object
*/
const TYPE_GAMUT = 'gamut';
public const TYPE_GAMUT = 'gamut';

/**
* Identify a Content object
*/
const TYPE_CONTENT = 'content';
public const TYPE_CONTENT = 'content';

/**
* Identify a Template object
*/
const TYPE_TEMPLATE = 'template';
public const TYPE_TEMPLATE = 'template';

/**
* Interface all OutputFormat objects must implement
*/
const OUTPUTFORMAT_INTERFACE = 'MarkdownExtended\API\OutputFormatInterface';
public const OUTPUTFORMAT_INTERFACE = 'MarkdownExtended\API\OutputFormatInterface';

/**
* Interface all Gamut (filter) objects must implement
*/
const GAMUT_INTERFACE = 'MarkdownExtended\API\GamutInterface';
public const GAMUT_INTERFACE = 'MarkdownExtended\API\GamutInterface';

/**
* Interface all Content objects must implement
*/
const CONTENT_INTERFACE = 'MarkdownExtended\API\ContentInterface';
public const CONTENT_INTERFACE = 'MarkdownExtended\API\ContentInterface';

/**
* Interface all Template objects must implement
*/
const TEMPLATE_INTERFACE = 'MarkdownExtended\API\TemplateInterface';
public const TEMPLATE_INTERFACE = 'MarkdownExtended\API\TemplateInterface';

/**
* Dirname of internal resources
*/
const RESOURCE_TEMPLATE = 'template';
public const RESOURCE_TEMPLATE = 'template';

/**
* Dirname of internal configuration files
*/
const RESOURCE_CONFIG = 'config';
public const RESOURCE_CONFIG = 'config';

/**
* Internal templates mask
*/
const RESOURCE_TEMPLATE_MASK = 'default-%s.tpl';
public const RESOURCE_TEMPLATE_MASK = 'default-%s.tpl';

/**
* Internal configuration mask
*/
const RESOURCE_CONFIG_MASK = 'config-%s.ini';
public const RESOURCE_CONFIG_MASK = 'config-%s.ini';

/**
* @var \MarkdownExtended\Util\Registry
Expand All @@ -91,7 +91,7 @@ class Kernel
*/
private function __construct()
{
$this->_registry = new Registry;
$this->_registry = new Registry();
}

/**
Expand All @@ -112,13 +112,13 @@ public static function getInstance()
*/
public static function createInstance()
{
self::$_instance = new self;
self::set('config', new Registry);
self::$_instance = new self();
self::set('config', new Registry());
}

// -----------------
// Services management
// -----------------
// -----------------
// Services management
// -----------------

/**
* Get the API's interface by object's type
Expand Down Expand Up @@ -245,16 +245,18 @@ public static function validate($class_name, $type, $real_name = null)
throw new UnexpectedValueException(
sprintf(
'Object "%s" of type "%s" must implement API interface "%s"',
($real_name ?: $class_name), $type, self::getApiFromType($type)
($real_name ?: $class_name),
$type,
self::getApiFromType($type)
)
);
}
return true;
}

// -----------------
// Configuration aliases
// -----------------
// -----------------
// Configuration aliases
// -----------------

/**
* Gets a configuration entry
Expand Down Expand Up @@ -341,7 +343,10 @@ public static function applyConfig($name, array $params, $default = null)
* @return null
*/
protected static function _configRecursiveIterator(
$type = 'get', $index, $value = null, $default = null
$type = 'get',
$index,
$value = null,
$default = null
) {
$result = null;
$indexer = new \ArrayIterator(explode('.', $index));
Expand Down Expand Up @@ -369,9 +374,9 @@ protected static function _configRecursiveIterator(
return $result ?: $default;
}

// -----------------
// App resources finder
// -----------------
// -----------------
// App resources finder
// -----------------

/**
* Finds an internal resource file by type
Expand All @@ -383,9 +388,9 @@ protected static function _configRecursiveIterator(
public static function getResourcePath($name, $type)
{
if ($type === self::RESOURCE_CONFIG || $type === self::RESOURCE_TEMPLATE) {
$local_path = realpath(Helper::getPath(array(
dirname(__DIR__), 'Resources', strtolower($type)
)));
$local_path = realpath(Helper::getPath([
dirname(__DIR__), 'Resources', strtolower($type),
]));

if (file_exists($local = $local_path . DIRECTORY_SEPARATOR . $name)) {
return $local;
Expand Down
4 changes: 2 additions & 2 deletions src/MarkdownExtended/API/OutputFormatInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface OutputFormatInterface
*
* @return string
*/
public function buildTag($tag_name, $content = null, array $attributes = array());
public function buildTag($tag_name, $content = null, array $attributes = []);

/**
* @param string $content Concerned content
Expand All @@ -33,7 +33,7 @@ public function buildTag($tag_name, $content = null, array $attributes = array()
*
* @return string
*/
public function getTagString($content, $tag_name, array $attributes = array());
public function getTagString($content, $tag_name, array $attributes = []);

/**
* Gets the notes list as string
Expand Down
Loading

0 comments on commit 5a34609

Please sign in to comment.