Skip to content

Commit

Permalink
Merge pull request #3 from Xety/psr2
Browse files Browse the repository at this point in the history
Added PSR2 as default CS
  • Loading branch information
Emeric authored Nov 10, 2016
2 parents 70568c5 + 32651ad commit 56158a5
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 152 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md → .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* Screenshots and code exemple are welcome in the issues.

* You want to implement a new feature or fix a bug ? Please follow this guide :
* Your code **must follow** the [Coding Standard of CakePHP](http://book.cakephp.org/3.0/en/contributing/cakephp-coding-conventions.html). Check the [cakephp-codesniffer](https://github.com/cakephp/cakephp-codesniffer) repository to setup the CakePHP standard.
* Your code **must follow** the [PSR2 Coding Standard](http://www.php-fig.org/psr/psr-2/). Check the [squizlabs/php_codesniffer](https://github.com/squizlabs/php_codesniffer) repository to setup the codesniffer.
* You must **add Test Cases** for your new feature. Test Cases ensure that the application will continue to working in the future.
* Your PR should be on the `master` branch. The master branch is actually the dev branch.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_script:
- composer install --prefer-dist --no-interaction --dev

script:
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src; fi"
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=PSR2 ./src; fi"

notifications:
email: false
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ This module has the following command and it require to be admin of the bot by d
|`!module loaded`|Show the list of the loaded modules.|E.g `Modules loaded : Basic, Module, Developer.`|

# Contribute
[Follow this guide to contribute](https://github.com/Xety/Skinny/blob/master/CONTRIBUTING.md)
[Follow this guide to contribute](https://github.com/Xety/Skinny/blob/master/.github/CONTRIBUTING.md)

# Ressources
* [CakePHP](https://github.com/cakephp/cakephp)
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"require-dev": {
"phpunit/phpunit": "*",
"cakephp/cakephp-codesniffer": "~2.0"
"squizlabs/php_codesniffer": "3.0.x-dev"
},
"autoload": {
"psr-4": {
Expand Down
42 changes: 21 additions & 21 deletions src/Configure/Configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Configure
*
* @var array
*/
protected static $_values = [
protected static $values = [
'debug' => 0
];

Expand All @@ -28,7 +28,7 @@ class Configure
*
* @return void
*/
protected static $_hasIniSet = null;
protected static $hasIniSet = null;

/**
* Used to store a dynamic variable in Configure.
Expand Down Expand Up @@ -60,13 +60,13 @@ public static function write($config, $value = null)
$config = [$config => $value];
}
foreach ($config as $name => $value) {
static::$_values = Hash::insert(static::$_values, $name, $value);
static::$values = Hash::insert(static::$values, $name, $value);
}
if (isset($config['debug'])) {
if (static::$_hasIniSet === null) {
static::$_hasIniSet = function_exists('ini_set');
if (static::$hasIniSet === null) {
static::$hasIniSet = function_exists('ini_set');
}
if (static::$_hasIniSet) {
if (static::$hasIniSet) {
ini_set('display_errors', $config['debug'] ? 1 : 0);
}
}
Expand All @@ -91,10 +91,10 @@ public static function write($config, $value = null)
public static function read($var = null)
{
if ($var === null) {
return static::$_values;
return static::$values;
}

return Hash::get(static::$_values, $var);
return Hash::get(static::$values, $var);
}

/**
Expand All @@ -110,7 +110,7 @@ public static function check($var)
return false;
}

return Hash::get(static::$_values, $var) !== null;
return Hash::get(static::$values, $var) !== null;
}

/**
Expand All @@ -128,7 +128,7 @@ public static function check($var)
*/
public static function delete($var)
{
static::$_values = Hash::remove(static::$_values, $var);
static::$values = Hash::remove(static::$values, $var);
}

/**
Expand All @@ -144,17 +144,17 @@ public static function delete($var)
public static function consume($var)
{
$simple = strpos($var, '.') === false;
if ($simple && !isset(static::$_values[$var])) {
if ($simple && !isset(static::$values[$var])) {
return null;
}
if ($simple) {
$value = static::$_values[$var];
unset(static::$_values[$var]);
$value = static::$values[$var];
unset(static::$values[$var]);

return $value;
}
$value = Hash::get(static::$_values, $var);
static::$_values = Hash::remove(static::$_values, $var);
$value = Hash::get(static::$values, $var);
static::$_values = Hash::remove(static::$values, $var);

return $value;
}
Expand All @@ -181,7 +181,7 @@ public static function consume($var)
*/
public static function load($key, $merge = true)
{
$file = static::_getFilePath($key);
$file = static::getFilePath($key);

$return = include $file;
if (!is_array($return)) {
Expand All @@ -203,7 +203,7 @@ public static function load($key, $merge = true)
*
* @return string
*/
protected static function _getFilePath($key)
protected static function getFilePath($key)
{
return CONFIG . $key . static::EXT;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ protected static function _getFilePath($key)
*/
public static function dump($key, $keys = [])
{
$values = static::$_values;
$values = static::$values;

if (!empty($keys) && is_array($keys)) {
$values = array_intersect_key($values, array_flip($keys));
Expand All @@ -252,12 +252,12 @@ public static function dump($key, $keys = [])
*/
public static function version()
{
if (!isset(static::$_values['Bot']['version'])) {
if (!isset(static::$values['Bot']['version'])) {
require ROOT . DS . 'config' . DS . 'version.php';
static::write($config);
}

return static::$_values['Bot']['version'];
return static::$values['Bot']['version'];
}

/**
Expand All @@ -267,7 +267,7 @@ public static function version()
*/
public static function clear()
{
static::$_values = [];
static::$values = [];

return true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Configure/Configure/Exception/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ class Exception extends \RuntimeException
*
* @var array
*/
protected $_attributes = [];
protected $attributes = [];

/**
* Template string that has attributes sprintf()'ed into it.
*
* @var string
*/
protected $_messageTemplate = '';
protected $messageTemplate = '';

/**
* Array of headers to be passed to \Bot\Network\Response::header()
*
* @var array
*/
protected $_responseHeaders = null;
protected $responseHeaders = null;

/**
* Constructor.
Expand All @@ -39,8 +39,8 @@ class Exception extends \RuntimeException
public function __construct($message, $code = 500, $previous = null)
{
if (is_array($message)) {
$this->_attributes = $message;
$message = vsprintf($this->_messageTemplate, $message);
$this->attributes = $message;
$message = vsprintf($this->messageTemplate, $message);
}
parent::__construct($message, $code, $previous);
}
Expand All @@ -52,6 +52,6 @@ public function __construct($message, $code = 500, $previous = null)
*/
public function getAttributes()
{
return $this->_attributes;
return $this->attributes;
}
}
50 changes: 25 additions & 25 deletions src/Configure/InstanceConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ trait InstanceConfigTrait
*
* @var array
*/
protected $_config = [];
protected $config = [];

/**
* Whether the config property has already been configured with defaults.
*
* @var bool
*/
protected $_configInitialized = false;
protected $configInitialized = false;

/**
* ### Usage
Expand Down Expand Up @@ -62,18 +62,18 @@ trait InstanceConfigTrait
*/
public function config($key = null, $value = null, $merge = true)
{
if (!$this->_configInitialized) {
$this->_config = $this->_defaultConfig;
$this->_configInitialized = true;
if (!$this->configInitialized) {
$this->config = $this->defaultConfig;
$this->configInitialized = true;
}

if (is_array($key) || func_num_args() >= 2) {
$this->_configWrite($key, $value, $merge);
$this->configWrite($key, $value, $merge);

return $this;
}

return $this->_configRead($key);
return $this->configRead($key);
}

/**
Expand All @@ -98,12 +98,12 @@ public function config($key = null, $value = null, $merge = true)
*/
public function configShallow($key, $value = null)
{
if (!$this->_configInitialized) {
$this->_config = $this->_defaultConfig;
$this->_configInitialized = true;
if (!$this->configInitialized) {
$this->config = $this->defaultConfig;
$this->configInitialized = true;
}

$this->_configWrite($key, $value, 'shallow');
$this->configWrite($key, $value, 'shallow');

return $this;
}
Expand All @@ -114,17 +114,17 @@ public function configShallow($key, $value = null)
* @param string|null $key Key to read.
* @return mixed
*/
protected function _configRead($key)
protected function configRead($key)
{
if ($key === null) {
return $this->_config;
return $this->config;
}

if (strpos($key, '.') === false) {
return isset($this->_config[$key]) ? $this->_config[$key] : null;
return isset($this->config[$key]) ? $this->config[$key] : null;
}

$return = $this->_config;
$return = $this->config;

foreach (explode('.', $key) as $k) {
if (!is_array($return) || !isset($return[$k])) {
Expand All @@ -149,10 +149,10 @@ protected function _configRead($key)
*
* @throws \Skinny\Configure\Configure\Exception\Exception if attempting to clobber existing config
*/
protected function _configWrite($key, $value, $merge = false)
protected function configWrite($key, $value, $merge = false)
{
if (is_string($key) && $value === null) {
$this->_configDelete($key);
$this->configDelete($key);

return;
}
Expand All @@ -164,29 +164,29 @@ protected function _configWrite($key, $value, $merge = false)
$update = [$key => $value];
}
if ($merge === 'shallow') {
$this->_config = array_merge($this->_config, Hash::expand($update));
$this->config = array_merge($this->config, Hash::expand($update));
} else {
$this->_config = Hash::merge($this->_config, Hash::expand($update));
$this->config = Hash::merge($this->config, Hash::expand($update));
}

return;
}

if (is_array($key)) {
foreach ($key as $k => $val) {
$this->_configWrite($k, $val);
$this->configWrite($k, $val);
}

return;
}

if (strpos($key, '.') === false) {
$this->_config[$key] = $value;
$this->config[$key] = $value;

return;
}

$update =& $this->_config;
$update =& $this->config;
$stack = explode('.', $key);

foreach ($stack as $k) {
Expand All @@ -212,15 +212,15 @@ protected function _configWrite($key, $value, $merge = false)
*
* @throws \Skinny\Configure\Configure\Exception\Exception if attempting to clobber existing config
*/
protected function _configDelete($key)
protected function configDelete($key)
{
if (strpos($key, '.') === false) {
unset($this->_config[$key]);
unset($this->config[$key]);

return;
}

$update =& $this->_config;
$update =& $this->config;
$stack = explode('.', $key);
$length = count($stack);

Expand Down
Loading

0 comments on commit 56158a5

Please sign in to comment.