Completed
Branch master (6b3d37)
by Yuichi
05:38
created
src/Imports/AbstractImport.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -17,24 +17,24 @@  discard block
 block discarded – undo
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) ) {
35
-                for($i=0;$i<count($model);$i++) {
36
-                    if ( isset($this->config[$table][$i]) ) {
37
-                        $this->setModel($model[$i],$this->config[$table][$i],$csv,$table);
33
+        foreach ($models as $table => $model) {
34
+            if (is_array($model)) {
35
+                for ($i = 0; $i < count($model); $i++) {
36
+                    if (isset($this->config[$table][$i])) {
37
+                        $this->setModel($model[$i], $this->config[$table][$i], $csv, $table);
38 38
                     } else {
39 39
                         throw new \Exception('設定ファイルが正しくないか、構成が異なっています。table=' . $table);
40 40
                     }
@@ -44,23 +44,23 @@  discard block
 block discarded – undo
44 44
         return true;
45 45
     }
46 46
 
47
-    public function setModel($model,$config,$csv,$table)
47
+    public function setModel($model, $config, $csv, $table)
48 48
     {
49
-        foreach ( $config as $key => $rec ) {
50
-            if ( isset($rec['func']) == true && $rec['func'] ) {
49
+        foreach ($config as $key => $rec) {
50
+            if (isset($rec['func']) == true && $rec['func']) {
51 51
                 $func = $rec['func'];
52 52
                 $col = isset($rec['csv']) ? $rec['csv'] : null;
53
-                if ( strpos($col,",") !== false ) {
54
-                    $col = explode(",",$col);
53
+                if (strpos($col, ",") !== false) {
54
+                    $col = explode(",", $col);
55 55
                 }
56
-                if ( method_exists($this,$func) === true ) {
57
-                    $this->$func($model,$key,$csv,$col);
56
+                if (method_exists($this, $func) === true) {
57
+                    $this->$func($model, $key, $csv, $col);
58 58
                 } else {
59 59
                     throw new \Exception(get_class($this) . 'に関数=' . $func . 'が実装されていません。');
60 60
                 }
61
-            } elseif ( isset($rec['csv']) && is_numeric($rec['csv']) == true && isset($csv[($rec['csv']+0)-1]) ) {
61
+            } elseif (isset($rec['csv']) && is_numeric($rec['csv']) == true && isset($csv[($rec['csv']+0)-1])) {
62 62
                 $model->$key = $csv[($rec['csv']+0)-1];
63
-            } elseif ( isset($rec['csv']) && is_numeric($rec['csv']) == false && isset($csv[$rec['csv']]) ) {
63
+            } elseif (isset($rec['csv']) && is_numeric($rec['csv']) == false && isset($csv[$rec['csv']])) {
64 64
                 $model->$key = $csv[$rec['csv']];
65 65
             } else {
66 66
                 $model->$key = null;
Please login to merge, or discard this patch.
src/Helpers/string.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/Helpers/date.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,29 +1,29 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/Helpers/format.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/Imports/CsvReaderTrait.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/Imports/DummyImport.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/TreeStructureTrait.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -18,27 +18,27 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
             }
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,8 +19,12 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
                 }
Please login to merge, or discard this patch.
src/HelpersServiceProvider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@
 block discarded – undo
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
         }
Please login to merge, or discard this patch.