Skip to content

Commit

Permalink
コード整形
Browse files Browse the repository at this point in the history
  • Loading branch information
ateliee committed Oct 5, 2019
1 parent 10dcfd8 commit aba644a
Show file tree
Hide file tree
Showing 24 changed files with 210 additions and 130 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,17 @@ customer |o-ri-o{ order
```

## コードチェック
CodeSnifferを利用

```
vendor/bin/phpcs src
# レポート出力
composer report
# 自動修正
composer convert
```



## 参考
* [Plant UML](http://plantuml.com/ja/)
* [Real World PlantUML](https://real-world-plantuml.com/)
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"scripts": {
"test": "phpunit",
"check": "php vendor/bin/phpcs --standard=phpcs.xml",
"report": "php vendor/bin/phpcs -sq --no-colors --report-diff=./logs/report-diff.log --report-full=./logs/report-full.log --standard=phpcs.xml"
"report": "php vendor/bin/phpcs -sq --no-colors --report-diff=./logs/report-diff.log --report-full=./logs/report-full.log --standard=phpcs.xml",
"convert": "php vendor/bin/phpcbf --standard=phpcs.xml"
},
"config": {
"platform": {
Expand Down
5 changes: 4 additions & 1 deletion src/PlantUMLParser/Exception/FileOpenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@
*/
namespace Ateliee\PlantUMLParser\Exception;

class FileOpenException extends PUMLException {}
class FileOpenException extends PUMLException
{

}
6 changes: 5 additions & 1 deletion src/PlantUMLParser/Exception/InvalidParamaterException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
namespace Ateliee\PlantUMLParser\Exception;

/**
* Invalid Paramater Error
*/
class InvalidParamaterException extends PUMLException {}
class InvalidParamaterException extends PUMLException
{

}
5 changes: 3 additions & 2 deletions src/PlantUMLParser/Exception/PUMLException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Ateliee\PlantUMLParser\Exception;

class PUMLException extends \Exception {
class PUMLException extends \Exception
{

}
}
6 changes: 5 additions & 1 deletion src/PlantUMLParser/Exception/ParseInvalidException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
namespace Ateliee\PlantUMLParser\Exception;

/**
* Invalid Parse Error
*/
class ParseInvalidException extends PUMLException {}
class ParseInvalidException extends PUMLException
{

}
6 changes: 5 additions & 1 deletion src/PlantUMLParser/Exception/SyntaxException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
namespace Ateliee\PlantUMLParser\Exception;

/**
* Syntax Error
*/
class SyntaxException extends PUMLException {}
class SyntaxException extends PUMLException
{

}
21 changes: 12 additions & 9 deletions src/PlantUMLParser/PUMLElement.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php
namespace Ateliee\PlantUMLParser;

abstract class PUMLElement {
abstract class PUMLElement
{

/**
* get PUML Element name
*
* @return string
*/
public static function name(){
public static function name()
{
$c = explode('\\', get_called_class());
$c = end($c);
if(preg_match('/^PUML(.+)$/', $c, $matchs)){
if (preg_match('/^PUML(.+)$/', $c, $matchs)) {
$c = $matchs[1];
}
return $c;
Expand Down Expand Up @@ -62,17 +64,17 @@ public function getComment()
*/
public function getOutputComment($indent = '')
{
if($this->comment){
if ($this->comment) {
$list = explode(PHP_EOL, $this->comment);
$before = '/\'';
$after = '\'/';
if(count($list) > 1){
if (count($list) > 1) {
$before = $indent.$before.PHP_EOL;
$after = PHP_EOL.$indent.$after;
$list = array_map(function($str) use ($indent){
$list = array_map(function ($str) use ($indent) {
return $indent.' '.$str;
}, $list);
}else{
} else {
$before = $indent.$before.' ';
$after = ' '.$after;
}
Expand All @@ -96,13 +98,14 @@ public function getValue()
* @param int $indent
* @return mixed
*/
public abstract function str($current_indent, $indent);
abstract public function str($current_indent, $indent);

/**
* @param int $indent
* @return string
*/
protected function make_indent($indent = 2){
protected function makeIndent($indent = 2)
{
return str_repeat(' ', $indent);
}
}
15 changes: 8 additions & 7 deletions src/PlantUMLParser/PUMLElementBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/**
* @property string $value
*/
class PUMLElementBlock extends PUMLElement implements \ArrayAccess {
class PUMLElementBlock extends PUMLElement implements \ArrayAccess
{

/**
* @var PUMLElementList $childs
Expand All @@ -25,15 +26,17 @@ public function __construct($value)
* @param PUMLElement $elm
* @return $this
*/
public function add($elm){
public function add($elm)
{
$this->childs->add($elm);
return $this;
}

/**
* @return string
*/
public function getValueLabel(){
public function getValueLabel()
{
return $this->value;
}

Expand All @@ -46,9 +49,9 @@ public function str($current_indent, $indent)
{
$str = $this->getOutputComment($current_indent);
$str .= $current_indent.sprintf('%s{', $this->getValueLabel()).PHP_EOL;
$str .= $this->childs->str($current_indent.$this->make_indent($indent), $indent);
$str .= $this->childs->str($current_indent.$this->makeIndent($indent), $indent);
$str .= $current_indent.'}';
if(!$current_indent){
if (!$current_indent) {
$str .= PHP_EOL;
}
return $str;
Expand Down Expand Up @@ -78,6 +81,4 @@ public function offsetUnset($offset)
{
unset($this->childs[$offset]);
}


}
17 changes: 10 additions & 7 deletions src/PlantUMLParser/PUMLElementList.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
namespace Ateliee\PlantUMLParser;

use Ateliee\PlantUMLParser\Exception\InvalidParamaterException;
use Ateliee\PlantUMLParser\Exception\PUMLException;

/**
* @property PUMLElement[] $value
*/
class PUMLElementList extends PUMLElement implements \ArrayAccess, \Countable {
class PUMLElementList extends PUMLElement implements \ArrayAccess, \Countable
{

/**
* PUMLElementList constructor.
Expand All @@ -23,19 +25,20 @@ public function __construct()
* @throws PUMLException
* @return $this
*/
public function add($elm){
public function add($elm)
{

$elm = func_get_args();
if(count($elm) == 1){
if (count($elm) == 1) {
$elm = current($elm);
}
if(is_array($elm)){
foreach($elm as $e){
if (is_array($elm)) {
foreach ($elm as $e) {
$this->add($e);
}
return $this;
}
if(!($elm instanceof PUMLElement)){
if (!($elm instanceof PUMLElement)) {
throw new InvalidParamaterException();
}
$this->value[] = $elm;
Expand All @@ -50,7 +53,7 @@ public function add($elm){
public function str($current_indent, $indent)
{
$str = $this->getOutputComment($current_indent);
foreach($this->value as $v){
foreach ($this->value as $v) {
$str .= $v->str($current_indent, $indent).PHP_EOL;
}
return $str;
Expand Down
5 changes: 2 additions & 3 deletions src/PlantUMLParser/PUMLKeyValue.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Ateliee\PlantUMLParser;

class PUMLKeyValue extends PUMLElement {
class PUMLKeyValue extends PUMLElement
{

/**
* @var string $key
Expand All @@ -28,6 +29,4 @@ public function __toString()
{
return sprintf('%s %s', $this->key, $this->value);
}


}
21 changes: 11 additions & 10 deletions src/PlantUMLParser/PUMLObject.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Ateliee\PlantUMLParser;

class PUMLObject extends PUMLElementBlock {
class PUMLObject extends PUMLElementBlock
{

/**
* @var string $name
Expand Down Expand Up @@ -36,14 +37,14 @@ public function __construct($type, $name, $alias = null, $attributes = null)
/**
* @return string
*/
public function getValueLabel(){
return sprintf('%s %s%s%s',
$this->value,
$this->alias ? "\"".$this->name."\"" : $this->name,
$this->alias ? ' as '.$this->alias : '',
$this->attributes ? ' '.$this->attributes : ''
);
public function getValueLabel()
{
return sprintf(
'%s %s%s%s',
$this->value,
$this->alias ? "\"".$this->name."\"" : $this->name,
$this->alias ? ' as '.$this->alias : '',
$this->attributes ? ' '.$this->attributes : ''
);
}


}
3 changes: 2 additions & 1 deletion src/PlantUMLParser/PUMLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
/**
* Class PUMLParser
*/
class PUMLParser extends PUMLParse {
class PUMLParser extends PUMLParse
{

use PUMLOutputTrait;
}
3 changes: 2 additions & 1 deletion src/PlantUMLParser/PUMLStr.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Ateliee\PlantUMLParser;

class PUMLStr extends PUMLElement {
class PUMLStr extends PUMLElement
{

public function str($current_indent, $indent)
{
Expand Down
Loading

0 comments on commit aba644a

Please sign in to comment.