| @@ -2,7 +2,6 @@ | ||
| 2 | 2 | namespace Sonar\Common\Imports; | 
| 3 | 3 | |
| 4 | 4 | use Symfony\Component\Yaml\Yaml; | 
| 5 | -use Symfony\Component\Yaml\Exception\ParseException; | |
| 6 | 5 | use File; | 
| 7 | 6 | |
| 8 | 7 | abstract class AbstractImport | 
| @@ -17,25 +17,25 @@ discard block | ||
| 17 | 17 | public function setConfig($config_file) | 
| 18 | 18 |      { | 
| 19 | 19 | $config = Yaml::parse($config_file); | 
| 20 | -        if ( is_array($config) === false  ) { | |
| 20 | +        if (is_array($config) === false) { | |
| 21 | 21 | $config = Yaml::parse(File::get($config_file)); | 
| 22 | 22 | } | 
| 23 | -        if ( is_array($config) ) { | |
| 24 | - $this->config = array_merge($this->config,$config); | |
| 23 | +        if (is_array($config)) { | |
| 24 | + $this->config = array_merge($this->config, $config); | |
| 25 | 25 | } | 
| 26 | 26 | } | 
| 27 | 27 | public function getConfig() | 
| 28 | 28 |      { | 
| 29 | 29 | return $this->config; | 
| 30 | 30 | } | 
| 31 | - public function setModels($models,$csv) | |
| 31 | + public function setModels($models, $csv) | |
| 32 | 32 |      { | 
| 33 | -        foreach ( $models as $table => $model ) { | |
| 34 | -            if ( is_array($model) ) { | |
| 33 | +        foreach ($models as $table => $model) { | |
| 34 | +            if (is_array($model)) { | |
| 35 | 35 | $total = count($model); | 
| 36 | -                for($i=0;$i<$total;$i++) { | |
| 37 | -                    if ( isset($this->config[$table][$i]) ) { | |
| 38 | - $this->setModel($model[$i],$this->config[$table][$i],$csv,$table); | |
| 36 | +                for ($i = 0; $i < $total; $i++) { | |
| 37 | +                    if (isset($this->config[$table][$i])) { | |
| 38 | + $this->setModel($model[$i], $this->config[$table][$i], $csv, $table); | |
| 39 | 39 |                      } else { | 
| 40 | 40 |                          throw new \Exception('設定ファイルが正しくないか、構成が異なっています。table=' . $table); | 
| 41 | 41 | } | 
| @@ -45,23 +45,23 @@ discard block | ||
| 45 | 45 | return true; | 
| 46 | 46 | } | 
| 47 | 47 | |
| 48 | - public function setModel($model,$config,$csv,$table) | |
| 48 | + public function setModel($model, $config, $csv, $table) | |
| 49 | 49 |      { | 
| 50 | -        foreach ( $config as $key => $rec ) { | |
| 51 | -            if ( isset($rec['func']) === true && $rec['func'] ) { | |
| 50 | +        foreach ($config as $key => $rec) { | |
| 51 | +            if (isset($rec['func']) === true && $rec['func']) { | |
| 52 | 52 | $func = $rec['func']; | 
| 53 | 53 | $col = isset($rec['csv']) ? $rec['csv'] : null; | 
| 54 | -                if ( strpos($col,",") !== false ) { | |
| 55 | -                    $col = explode(",",$col); | |
| 54 | +                if (strpos($col, ",") !== false) { | |
| 55 | +                    $col = explode(",", $col); | |
| 56 | 56 | } | 
| 57 | -                if ( method_exists($this,$func) === true ) { | |
| 58 | - $this->$func($model,$key,$csv,$col); | |
| 57 | +                if (method_exists($this, $func) === true) { | |
| 58 | + $this->$func($model, $key, $csv, $col); | |
| 59 | 59 |                  } else { | 
| 60 | 60 | throw new \Exception(get_class($this) . 'に関数=' . $func . 'が実装されていません。'); | 
| 61 | 61 | } | 
| 62 | -            } elseif ( isset($rec['csv']) && is_numeric($rec['csv']) === true && isset($csv[($rec['csv']+0)-1]) ) { | |
| 62 | +            } elseif (isset($rec['csv']) && is_numeric($rec['csv']) === true && isset($csv[($rec['csv']+0)-1])) { | |
| 63 | 63 | $model->$key = $csv[($rec['csv']+0)-1]; | 
| 64 | -            } elseif ( isset($rec['csv']) && is_numeric($rec['csv']) === false && isset($csv[$rec['csv']]) ) { | |
| 64 | +            } elseif (isset($rec['csv']) && is_numeric($rec['csv']) === false && isset($csv[$rec['csv']])) { | |
| 65 | 65 | $model->$key = $csv[$rec['csv']]; | 
| 66 | 66 |              } else { | 
| 67 | 67 | $model->$key = null; | 
| @@ -1,13 +1,13 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | -if ( ! function_exists('strcat') ) {
 | |
| 3 | +if ( ! function_exists('strcat')) {
 | |
| 4 | 4 | function strcat() | 
| 5 | 5 |      {
 | 
| 6 | 6 | $args = func_get_args(); | 
| 7 | 7 | $str = ''; | 
| 8 | 8 | |
| 9 | -        foreach ( $args as $rec ) {
 | |
| 10 | -            if ( $rec ) {
 | |
| 9 | +        foreach ($args as $rec) {
 | |
| 10 | +            if ($rec) {
 | |
| 11 | 11 | $str .= $rec; | 
| 12 | 12 |              } else {
 | 
| 13 | 13 | return null; | 
| @@ -1,29 +1,29 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | use Carbon\Carbon; | 
| 3 | 3 | |
| 4 | -if ( ! function_exists('strtodate') ) {
 | |
| 5 | - function strtodate($date,$format='Y/m/d') | |
| 4 | +if ( ! function_exists('strtodate')) {
 | |
| 5 | + function strtodate($date, $format = 'Y/m/d') | |
| 6 | 6 |      {
 | 
| 7 | -        if ( $date ) {
 | |
| 8 | - return date($format,strtotime($date)); | |
| 7 | +        if ($date) {
 | |
| 8 | + return date($format, strtotime($date)); | |
| 9 | 9 | } | 
| 10 | 10 | return null; | 
| 11 | 11 | } | 
| 12 | 12 | } | 
| 13 | 13 | |
| 14 | -if ( ! function_exists('ym') ) {
 | |
| 14 | +if ( ! function_exists('ym')) {
 | |
| 15 | 15 | function ym($ym) | 
| 16 | 16 |      {
 | 
| 17 | -        if ( $ym && $ym > 190001 ) {
 | |
| 18 | - return (floor($ym/100)) . '年' . ( floor($ym%100)) . '月'; | |
| 17 | +        if ($ym && $ym > 190001) {
 | |
| 18 | + return (floor($ym/100)) . '年' . (floor($ym%100)) . '月'; | |
| 19 | 19 | } | 
| 20 | 20 | return null; | 
| 21 | 21 | } | 
| 22 | 22 | } | 
| 23 | 23 | |
| 24 | -if ( ! function_exists('elapse_days') ) {
 | |
| 24 | +if ( ! function_exists('elapse_days')) {
 | |
| 25 | 25 | function elapse_days($timestamp) | 
| 26 | 26 |      {
 | 
| 27 | - return Carbon::createFromTimeStamp($timestamp)->diffInDays(Carbon::now(),false); | |
| 27 | + return Carbon::createFromTimeStamp($timestamp)->diffInDays(Carbon::now(), false); | |
| 28 | 28 | } | 
| 29 | 29 | } | 
| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | -if ( ! function_exists('numeric_format') ) {
 | |
| 3 | +if ( ! function_exists('numeric_format')) {
 | |
| 4 | 4 | function numeric_format($val) | 
| 5 | 5 |      {
 | 
| 6 | -        $number = str_replace(",","",$val);
 | |
| 6 | +        $number = str_replace(",", "", $val);
 | |
| 7 | 7 | |
| 8 | -        if ( is_numeric($number) ) {
 | |
| 9 | - $number = number_format($number,8); | |
| 10 | -            $number = preg_replace('/\.0+$/','',$number);
 | |
| 11 | -            $number = preg_replace('/(\.[0-9]*?)0+$/',"$1",$number);
 | |
| 8 | +        if (is_numeric($number)) {
 | |
| 9 | + $number = number_format($number, 8); | |
| 10 | +            $number = preg_replace('/\.0+$/', '', $number);
 | |
| 11 | +            $number = preg_replace('/(\.[0-9]*?)0+$/', "$1", $number);
 | |
| 12 | 12 | } | 
| 13 | 13 | return $number; | 
| 14 | 14 | } | 
| @@ -5,11 +5,11 @@ | ||
| 5 | 5 |  { | 
| 6 | 6 | abstract public function csvRecord(array $record); | 
| 7 | 7 | |
| 8 | - public function csvRead($file,$delimiter=",",$envlosure='"',$escape="\\",$length=1024*1024) | |
| 8 | + public function csvRead($file, $delimiter = ",", $envlosure = '"', $escape = "\\", $length = 1024*1024) | |
| 9 | 9 |      { | 
| 10 | -        if ( ($fp = @fopen($file,"r")) !== false ) { | |
| 10 | +        if (($fp = @fopen($file, "r")) !== false) { | |
| 11 | 11 | |
| 12 | -            while(($data = fgetcsv($fp,$length,$delimiter,$envlosure,$escape)) !== false ) { | |
| 12 | +            while (($data = fgetcsv($fp, $length, $delimiter, $envlosure, $escape)) !== false) { | |
| 13 | 13 | $this->csvRecord($data); | 
| 14 | 14 | } | 
| 15 | 15 | fclose($fp); | 
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 |      { | 
| 10 | 10 | |
| 11 | 11 | } | 
| 12 | - public function setName($model,$key,$csv,$col) | |
| 12 | + public function setName($model, $key, $csv, $col) | |
| 13 | 13 |      { | 
| 14 | 14 | |
| 15 | 15 | } | 
| @@ -18,27 +18,27 @@ discard block | ||
| 18 | 18 |      {
 | 
| 19 | 19 | $tree = isset($this->tree) ? $this->tree : []; | 
| 20 | 20 | |
| 21 | -        foreach ( $data as $rec ) {
 | |
| 22 | -            if ( is_object($rec) === false ) throw new Exception('data record must be object.');
 | |
| 23 | -            if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".');
 | |
| 24 | -            if ( isset($rec->parent_id) === false || ! $rec->parent_id ) {
 | |
| 21 | +        foreach ($data as $rec) {
 | |
| 22 | +            if (is_object($rec) === false) throw new Exception('data record must be object.');
 | |
| 23 | +            if (isset($rec->id) === false) throw new Exception('data record object does not have property => "id".');
 | |
| 24 | +            if (isset($rec->parent_id) === false || ! $rec->parent_id) {
 | |
| 25 | 25 | $rec->children = []; | 
| 26 | 26 | $tree[$rec->id] = $rec; | 
| 27 | 27 |              } else {
 | 
| 28 | - $this->addTree($tree,$rec); | |
| 28 | + $this->addTree($tree, $rec); | |
| 29 | 29 | } | 
| 30 | 30 | } | 
| 31 | 31 | $this->tree = $tree; | 
| 32 | 32 | } | 
| 33 | - protected function addTree(&$tree,$data) | |
| 33 | + protected function addTree(&$tree, $data) | |
| 34 | 34 |      {
 | 
| 35 | -        foreach ( $tree as $id => &$rec ) {
 | |
| 36 | -            if ( $data->parent_id == $id ) {
 | |
| 35 | +        foreach ($tree as $id => &$rec) {
 | |
| 36 | +            if ($data->parent_id == $id) {
 | |
| 37 | 37 | $data->children = []; | 
| 38 | 38 | $rec->children[$data->id] = $data; | 
| 39 | 39 | return; | 
| 40 | -            } elseif ( count($rec->children) ) {
 | |
| 41 | - $this->addTree($rec->children,$data); | |
| 40 | +            } elseif (count($rec->children)) {
 | |
| 41 | + $this->addTree($rec->children, $data); | |
| 42 | 42 | } | 
| 43 | 43 | unset($rec); | 
| 44 | 44 | } | 
| @@ -46,12 +46,12 @@ discard block | ||
| 46 | 46 | public function mergeCount($count_data) | 
| 47 | 47 |      {
 | 
| 48 | 48 | $tree = isset($this->tree) ? $this->tree : []; | 
| 49 | -        foreach ( $tree as &$rec ) {
 | |
| 50 | -            foreach ( $count_data as $count ) {
 | |
| 51 | -                if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".');
 | |
| 52 | -                if ( isset($count->id) === false ) throw new Exception('count data record object does not have property => "id".');
 | |
| 53 | -                if ( isset($count->count) === false ) throw new Exception('count data record object does not have property => "count".');
 | |
| 54 | -                if ( $rec->id == $count->id ) {
 | |
| 49 | +        foreach ($tree as &$rec) {
 | |
| 50 | +            foreach ($count_data as $count) {
 | |
| 51 | +                if (isset($rec->id) === false) throw new Exception('data record object does not have property => "id".');
 | |
| 52 | +                if (isset($count->id) === false) throw new Exception('count data record object does not have property => "id".');
 | |
| 53 | +                if (isset($count->count) === false) throw new Exception('count data record object does not have property => "count".');
 | |
| 54 | +                if ($rec->id == $count->id) {
 | |
| 55 | 55 | $rec->count = $count->count; | 
| 56 | 56 | } | 
| 57 | 57 | } | 
| @@ -19,8 +19,12 @@ discard block | ||
| 19 | 19 | $tree = isset($this->tree) ? $this->tree : []; | 
| 20 | 20 | |
| 21 | 21 |          foreach ( $data as $rec ) {
 | 
| 22 | -            if ( is_object($rec) === false ) throw new Exception('data record must be object.');
 | |
| 23 | -            if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".');
 | |
| 22 | +            if ( is_object($rec) === false ) {
 | |
| 23 | +                throw new Exception('data record must be object.');
 | |
| 24 | + } | |
| 25 | +            if ( isset($rec->id) === false ) {
 | |
| 26 | +                throw new Exception('data record object does not have property => "id".');
 | |
| 27 | + } | |
| 24 | 28 |              if ( isset($rec->parent_id) === false || ! $rec->parent_id ) {
 | 
| 25 | 29 | $rec->children = []; | 
| 26 | 30 | $tree[$rec->id] = $rec; | 
| @@ -48,9 +52,15 @@ discard block | ||
| 48 | 52 | $tree = isset($this->tree) ? $this->tree : []; | 
| 49 | 53 |          foreach ( $tree as &$rec ) {
 | 
| 50 | 54 |              foreach ( $count_data as $count ) {
 | 
| 51 | -                if ( isset($rec->id) === false ) throw new Exception('data record object does not have property => "id".');
 | |
| 52 | -                if ( isset($count->id) === false ) throw new Exception('count data record object does not have property => "id".');
 | |
| 53 | -                if ( isset($count->count) === false ) throw new Exception('count data record object does not have property => "count".');
 | |
| 55 | +                if ( isset($rec->id) === false ) {
 | |
| 56 | +                    throw new Exception('data record object does not have property => "id".');
 | |
| 57 | + } | |
| 58 | +                if ( isset($count->id) === false ) {
 | |
| 59 | +                    throw new Exception('count data record object does not have property => "id".');
 | |
| 60 | + } | |
| 61 | +                if ( isset($count->count) === false ) {
 | |
| 62 | +                    throw new Exception('count data record object does not have property => "count".');
 | |
| 63 | + } | |
| 54 | 64 |                  if ( $rec->id == $count->id ) {
 | 
| 55 | 65 | $rec->count = $count->count; | 
| 56 | 66 | } | 
| @@ -7,8 +7,8 @@ | ||
| 7 | 7 |  {
 | 
| 8 | 8 | public function register() | 
| 9 | 9 |      {
 | 
| 10 | -        foreach ( File::allFiles(__DIR__ . '/Helpers') as $rec ) {
 | |
| 11 | -            if ( preg_match("/\.php$/",$rec->getFilename()) ) {
 | |
| 10 | +        foreach (File::allFiles(__DIR__ . '/Helpers') as $rec) {
 | |
| 11 | +            if (preg_match("/\.php$/", $rec->getFilename())) {
 | |
| 12 | 12 | require_once($rec->getPathname()); | 
| 13 | 13 | } | 
| 14 | 14 | } |