Skip to content

Commit

Permalink
1. fix coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
scarwu committed Aug 14, 2018
1 parent 46b963d commit 886fc3f
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 245 deletions.
60 changes: 30 additions & 30 deletions src/Oni/CLI/IO.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ class IO extends Basic
*/
private function __construct()
{
$config_regex_rule = '/^-{2}(\w+(?:-\w+)?)(?:=(.+))?/';
$option_regex_rule = '/^-{1}(\w+)/';
$configRegexRule = '/^-{2}(\w+(?:-\w+)?)(?:=(.+))?/';
$optionRegexRule = '/^-{1}(\w+)/';

$argv = array_slice($_SERVER['argv'], 1);

// arguments
while ($argv) {
if (preg_match($config_regex_rule, $argv[0])) {
if (preg_match($configRegexRule, $argv[0])) {
break;
}

if (preg_match($option_regex_rule, $argv[0])) {
if (preg_match($optionRegexRule, $argv[0])) {
break;
}

Expand All @@ -61,19 +61,19 @@ private function __construct()

// options & configs
while ($value = array_shift($argv)) {
if (preg_match($config_regex_rule, $value, $match)) {
if (preg_match($configRegexRule, $value, $match)) {
$this->_configs[$match[1]] = isset($match[2]) ? $match[2] : null;
}

if (preg_match($option_regex_rule, $value, $match)) {
if (preg_match($optionRegexRule, $value, $match)) {
$this->_options[$match[1]] = null;

if (isset($argv[0])) {
if (preg_match($config_regex_rule, $argv[0])) {
if (preg_match($configRegexRule, $argv[0])) {
continue;
}

if (preg_match($option_regex_rule, $argv[0])) {
if (preg_match($optionRegexRule, $argv[0])) {
continue;
}

Expand Down Expand Up @@ -212,12 +212,12 @@ public function read()
*
* @param string $text
* @param function $callback
* @param string $text_color
* @param string $bg_color
* @param string $textColor
* @param string $bgColor
*
* @return string|bool
*/
public function ask($text, $callback = null, $text_color = null, $bg_color = null)
public function ask($text, $callback = null, $textColor = null, $bgColor = null)
{
if (null === $callback) {
$callback = function() {
Expand All @@ -226,7 +226,7 @@ public function ask($text, $callback = null, $text_color = null, $bg_color = nul
}

do {
$this->write($text, $text_color, $bg_color);
$this->write($text, $textColor, $bgColor);
} while (false === $callback($answer = $this->read()));

return $answer;
Expand All @@ -235,7 +235,7 @@ public function ask($text, $callback = null, $text_color = null, $bg_color = nul
/**
* @var array
*/
private static $text_color = [
private static $textColor = [
'black' => '0;30',
'red' => '0;31',
'green' => '0;32',
Expand All @@ -258,7 +258,7 @@ public function ask($text, $callback = null, $text_color = null, $bg_color = nul
/**
* @var array
*/
private static $bg_color = [
private static $bgColor = [
'black' => '0;40',
'red' => '0;41',
'green' => '0;42',
Expand All @@ -282,20 +282,20 @@ public function ask($text, $callback = null, $text_color = null, $bg_color = nul
* Color
*
* @param string $text
* @param string $text_color
* @param string $bg_color
* @param string $textColor
* @param string $bgColor
*
* @return string
*/
private function color($text, $text_color = null, $bg_color = null)
private function color($text, $textColor = null, $bgColor = null)
{
if (isset(self::$text_color[$text_color])) {
$color = self::$text_color[$text_color];
if (isset(self::$textColor[$textColor])) {
$color = self::$textColor[$textColor];
$text = "\033[{$color}m{$text}\033[m";
}

if (isset(self::$bg_color[$bg_color])) {
$color = self::$bg_color[$bg_color];
if (isset(self::$bgColor[$bgColor])) {
$color = self::$bgColor[$bgColor];
$text = "\033[{$color}m{$text}\033[m";
}

Expand All @@ -306,13 +306,13 @@ private function color($text, $text_color = null, $bg_color = null)
* Write data to STDOUT
*
* @param string $text
* @param string $text_color
* @param string $bg_color
* @param string $textColor
* @param string $bgColor
*/
public function write($text, $text_color = null, $bg_color = null)
public function write($text, $textColor = null, $bgColor = null)
{
if (null !== $text_color || null !== $bg_color) {
$text = $this->color($text, $text_color, $bg_color);
if (null !== $textColor || null !== $bgColor) {
$text = $this->color($text, $textColor, $bgColor);
}

fwrite(STDOUT, $text);
Expand All @@ -322,12 +322,12 @@ public function write($text, $text_color = null, $bg_color = null)
* Write data to STDOUT
*
* @param string $text
* @param string $bg_color
* @param string $bg_color
* @param string $bgColor
* @param string $bgColor
*/
public function writeln($text = '', $text_color = null, $bg_color = null)
public function writeln($text = '', $textColor = null, $bgColor = null)
{
$this->write("{$text}\n", $text_color, $bg_color);
$this->write("{$text}\n", $textColor, $bgColor);
}

/**
Expand Down
30 changes: 15 additions & 15 deletions src/Oni/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ class Loader
/**
* @var array
*/
private static $_namespace_list = [];
private static $_namespaceList = [];

/**
* Construct
*
* This function is private, so this class is singleton pattern
*/
private function __construct() {

private function __construct()
{
// Namespace Autoload Register
spl_autoload_register(function ($class_name) {
$class_name = trim($class_name, '\\');
spl_autoload_register(function ($className) {
$className = trim($className, '\\');

foreach (self::$_namespace_list as $namespace => $path_list) {
foreach (self::$_namespaceList as $namespace => $pathList) {
$pattern = '/^' . str_replace('\\', '\\\\', $namespace) . '/';

if (!preg_match($pattern, $class_name)) {
if (!preg_match($pattern, $className)) {
continue;
}

$class_name = str_replace($namespace, '', trim($class_name, '\\'));
$class_name = str_replace('\\', '/', trim($class_name, '\\'));
$className = str_replace($namespace, '', trim($className, '\\'));
$className = str_replace('\\', '/', trim($className, '\\'));

foreach ($path_list as $path) {
if (!file_exists("{$path}/{$class_name}.php")) {
foreach ($pathList as $path) {
if (!file_exists("{$path}/{$className}.php")) {
continue;
}

require "{$path}/{$class_name}.php";
require "{$path}/{$className}.php";

return true;
}
Expand Down Expand Up @@ -81,11 +81,11 @@ public static function append($namespace, $path)
$namespace = trim($namespace, '\\');
$path = rtrim($path, '/');

if (!isset(self::$_namespace_list[$namespace])) {
self::$_namespace_list[$namespace] = [];
if (!isset(self::$_namespaceList[$namespace])) {
self::$_namespaceList[$namespace] = [];
}

self::$_namespace_list[$namespace][] = $path;
self::$_namespaceList[$namespace][] = $path;

return true;
}
Expand Down
20 changes: 10 additions & 10 deletions src/Oni/Web/Req.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ public function query()
public function content()
{
switch ($this->contentType()) {
case 'application/x-www-form-urlencoded':
case 'multipart/form-data':
return $_POST;
case 'application/json':
return json_decode($this->body(), true);
default:
return $this->body();
case 'application/x-www-form-urlencoded':
case 'multipart/form-data':
return $_POST;
case 'application/json':
return json_decode($this->body(), true);
default:
return $this->body();
}
}

Expand All @@ -164,9 +164,9 @@ public function content()
public function file()
{
switch ($this->contentType()) {
case 'multipart/form-data':
default:
return $_FILES;
case 'multipart/form-data':
default:
return $_FILES;
}
}

Expand Down
Loading

0 comments on commit 886fc3f

Please sign in to comment.