Skip to content

Commit

Permalink
Fix CS & enforce CS check in travis-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoirotte committed Sep 3, 2016
1 parent f27d97c commit 1470810
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ before_script:

script:
- vendor/bin/phpunit --coverage-clover clover.xml
- vendor/bin/phpcs

after_success:
- composer require --dev satooshi/php-coveralls
Expand Down
9 changes: 9 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<ruleset name="Plop">
<description>Coding standard for Plop.</description>
<file>src/</file>
<arg value="vp"/>
<rule ref="PSR2"/>
<encoding>utf-8</encoding>
</ruleset>

14 changes: 12 additions & 2 deletions src/Interpolator/Percent.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,18 @@ public function interpolate($msg, array $args = array())
// Mapping = array(name => index)
$keys = array_keys($args);
$mapping = array_flip($keys);
$keys = array_map(function ($key) { return "%($key)"; }, $keys);
$values = array_map(function ($val) { return '%'.($val + 1).'$'; }, $mapping);
$keys = array_map(
function ($key) {
return "%($key)";
},
$keys
);
$values = array_map(
function ($val) {
return '%'.($val + 1).'$';
},
$mapping
);
$mapping = array_combine($keys, $values);
$msg = strtr($msg, $mapping);
return vsprintf($msg, array_values($args));
Expand Down
7 changes: 4 additions & 3 deletions src/Interpolator/Psr3.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ class Psr3 implements \Plop\InterpolatorInterface
* \copydoc Plop::InterpolatorInterface::interpolate()
*
* \note
* The following piece of code was taken as is
* from the PSR-3 documentation.
* The following piece of code was almost taken as is
* from the PSR-3 documentation with the addition of
* a visibility keyword.
*
* \copyright
* Copyright © Jordi Boggiano and other PSR-3 contributors.
*/
function interpolate($message, array $args = array())
public function interpolate($message, array $args = array())
{
$replace = array();
foreach ($args as $key => $val) {
Expand Down
7 changes: 4 additions & 3 deletions src/Psr3Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
*/
class Psr3Logger extends \Psr\Log\AbstractLogger
{
static $factory = null;
static $instance = null;
static protected $factory = null;
static protected $instance = null;

public function __construct()
{
Expand Down Expand Up @@ -68,7 +68,8 @@ public function log($level, $message, array $context = array())
// Switch to a factory that uses PSR3-interpolation.
$logging->setRecordFactory(static::$factory);
$logging->$level($message, $context);
} catch (Exception $e) {}
} catch (Exception $e) {
}

// Restore the original factory.
$logging->setRecordFactory($factory);
Expand Down
3 changes: 2 additions & 1 deletion src/RecordFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class RecordFactory implements \Plop\RecordFactoryInterface
{
protected $interpolator;

public function __construct(\Plop\InterpolatorInterface $interpolator = null) {
public function __construct(\Plop\InterpolatorInterface $interpolator = null)
{
if ($interpolator === null) {
$interpolator = new \Plop\Interpolator\Percent();
}
Expand Down

0 comments on commit 1470810

Please sign in to comment.