정적 분석기 결과 반영. 주로 배열 초기화. 변수 이름 실수 수정.

This commit is contained in:
2018-04-06 20:06:28 +09:00
parent 2bce82c73e
commit ffc0fc0c6f
20 changed files with 109 additions and 94 deletions
+3
View File
@@ -39,6 +39,9 @@ class CityHelper{
self::$listByNation = $listByNation;
}
/**
* @return array[]
*/
public static function getAllCities(){
if(self::$list === null){
self::generateCache();
+1 -2
View File
@@ -1,6 +1,5 @@
<?php
namespace sammo\Event\Action;
use sammo\Util;
use sammo\DB;
/**
@@ -51,7 +50,7 @@ class RaiseInvader extends \sammo\Event\Action{
private function moveCapital(){
$cities = array_map(function ($value) {
return $value;
}, INVADER_LIST);
}, static::INVADER_LIST);
$db = DB::db();
+3 -3
View File
@@ -17,9 +17,9 @@ class RegNPC extends \sammo\Event\Action{
int $intel,
int $birth = 160,
int $death = 300,
string $ego = null,
string $char = null,
string $text = null
$ego = null,
string $char = '',
string $text = ''
){
$this->npc = new \sammo\Scenario\NPC(
$affinity,
+6 -2
View File
@@ -36,7 +36,11 @@ abstract class Condition{
}
//array의 첫번째 값이 Condition이 아닌 경우에는 그냥 배열로 처리함.
return array_map(static::build, $conditionChain);
$result = [];
foreach($conditionChain as $condition){
$result[] = static::build($condition);
}
return $result;
}
protected static function _eval($arg, $env=null){
@@ -47,7 +51,7 @@ abstract class Condition{
];
}
if($arg instanceof Condition){
return $arg->checkCondition($env);
return $arg->eval($env);
}
throw new \InvalidArgumentException('평가 인자는 boolean이거나 Condition 클래스여야 합니다.');
}
+1 -1
View File
@@ -1,7 +1,7 @@
<?php
namespace sammo\Event\Condition;
class Interval extends sammo\Event\Condition{
class Interval extends \sammo\Event\Condition{
//TODO:구현
public function __construct(...$args){
throw new \BadMethodCallException('Not Yet Implmented.');
+6 -4
View File
@@ -3,6 +3,8 @@ namespace sammo\Event\Condition;
class Logic extends \sammo\Event\Condition{
private $mode = 'and';
/** @var \sammo\Event\Condition[] */
private $conditions = [];
const AVAILABLE_LOGIC_NAME = [
'not'=>false,
@@ -26,7 +28,7 @@ class Logic extends \sammo\Event\Condition{
}
public function eval($env=null){
switch($this->$mode){
switch($this->mode){
case 'not':
return $this->logicNot($env);
case 'and':
@@ -41,7 +43,7 @@ class Logic extends \sammo\Event\Condition{
}
private function logicNot($env){
$sub = self::_eval($this->conditions[0], $env);
$result = self::_eval($this->conditions[0], $env);
$result['value'] = !$result['value'];
$result['chain'][] = 'not';
return $result;
@@ -55,7 +57,7 @@ class Logic extends \sammo\Event\Condition{
$sub = self::_eval($cond, $env);
$chain[] = $sub['chain'];
if(!$sub['value']){
$result['value'] = false;
$value = false;
break;
}
}
@@ -74,7 +76,7 @@ class Logic extends \sammo\Event\Condition{
$sub = self::_eval($cond, $env);
$chain[] = $sub['chain'];
if($sub['value']){
$result['value'] = true;
$value = true;
break;
}
}
+5 -4
View File
@@ -18,22 +18,23 @@ class GameUnitConst{
static::_generate();
return static::$constID;
}
public static function byID($id): GameUnitDetail{
public static function byID(int $id): GameUnitDetail{
static::_generate();
return static::$constID[$id];
}
public static function byName($name): GameUnitDetail{
public static function byName(string $name): GameUnitDetail{
static::_generate();
return static::$constName[$name];
}
public static function byCity($city): GameUnitDetail{
public static function byCity(int $city): GameUnitDetail{
static::_generate();
return static::$constCity[$city];
}
public static function byRegion($region): GameUnitDetail{
public static function byRegion(int $region): GameUnitDetail{
static::_generate();
return static::$constRegion[$region];
}
+2 -1
View File
@@ -13,6 +13,7 @@ class GameUnitDetail{
public $recruitType;
public $recruitCondition;
public $recruitFirst;
public $info;
public function __construct(
int $id,
@@ -62,7 +63,7 @@ class GameUnitDetail{
}
if($this->recruitType == 2){
$cityLevel = CityConst::byID($id)->level;
$cityLevel = CityConst::byID($this->id)->level;
$cityLevel = CityConst::$regionMap[$cityLevel];
if(!key_exists($this->recruitCondition, $ownCities)){
+5 -2
View File
@@ -97,6 +97,7 @@ class NPC{
$name = 'ⓝ'.$this->name;
$pictureID = $this->pictureID;
if($env['show_img_level'] == 3 && $pictureID > 0){
$picture = "{$pictureID}.jpg";
}
@@ -107,11 +108,13 @@ class NPC{
$city = $this->locatedCity;
if($city === null){
if($nationID == 0){
$city = Util::choiceRandom(CityHelper::getAllCities())['id'];
$cityObj = Util::choiceRandom(CityHelper::getAllCities());
}
else{
$city = Util::choiceRandom(CityHelper::getAllNationCities($nationID))['id'];
$cityObj = Util::choiceRandom(CityHelper::getAllNationCities($nationID));
}
'@phan-var array<string,string|int> $cityObj';
$city = $cityObj['id'];
}
$experience = $age * 100;
+5 -4
View File
@@ -1,7 +1,6 @@
<?php
namespace sammo\Scenario;
use \sammo\DB;
use \sammo\Util;
class Nation{
private $id;
@@ -14,7 +13,7 @@ class Nation{
private $type;
private $nationLevel;
private $capital;
private $capital = null;
private $cities = [];
@@ -42,8 +41,10 @@ class Nation{
$this->type = $type;
$this->nationLevel = $nationLevel;
$this->cities = $cities;
$this->capital = count($cities)>0?$cities[0]:null;
if(count($cities)){
$this->capital = $this->cities[0];
}
}
public function setID(int $id){