@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | public function bigInt(string $name); |
10 | 10 | |
11 | - public function string(string $name,int $limit = 255); |
|
11 | + public function string(string $name, int $limit = 255); |
|
12 | 12 | |
13 | 13 | public function integer(string $name); |
14 | 14 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | public function foreignKey(string $name); |
32 | 32 | |
33 | - public function references(string $name,string $row = 'id'); |
|
33 | + public function references(string $name, string $row = 'id'); |
|
34 | 34 | |
35 | 35 | public function cascade(); |
36 | 36 |
@@ -6,37 +6,37 @@ |
||
6 | 6 | { |
7 | 7 | |
8 | 8 | |
9 | - public function createFile(string $fileName){ |
|
10 | - if(!file_exists(CONFIG_PATH)) mkdir(CONFIG_PATH,0777,true); |
|
9 | + public function createFile(string $fileName) { |
|
10 | + if (!file_exists(CONFIG_PATH)) mkdir(CONFIG_PATH, 0777, true); |
|
11 | 11 | $fileName = ucfirst($fileName); |
12 | - if(file_exists(CONFIG_PATH ."/" .$fileName . ".php")) throw new \Exception("Arquivo ja existe"); |
|
13 | - $file = fopen(CONFIG_PATH . "/" . $fileName . ".php",'w+'); |
|
14 | - if($file){ |
|
12 | + if (file_exists(CONFIG_PATH . "/" . $fileName . ".php")) throw new \Exception("Arquivo ja existe"); |
|
13 | + $file = fopen(CONFIG_PATH . "/" . $fileName . ".php", 'w+'); |
|
14 | + if ($file) { |
|
15 | 15 | $text = $this->copyFile(); |
16 | - $lines = $this->modifyClassName($text,$fileName); |
|
17 | - fwrite($file,$lines); |
|
16 | + $lines = $this->modifyClassName($text, $fileName); |
|
17 | + fwrite($file, $lines); |
|
18 | 18 | fclose($file); |
19 | 19 | } |
20 | 20 | } |
21 | 21 | |
22 | 22 | private function copyFile():string { |
23 | 23 | $fileNameReplace = __DIR__ . "/../ModelFile/ModelFile.php"; |
24 | - $fileCopy = fopen($fileNameReplace,'r'); |
|
25 | - $text = fread($fileCopy,filesize($fileNameReplace)); |
|
24 | + $fileCopy = fopen($fileNameReplace, 'r'); |
|
25 | + $text = fread($fileCopy, filesize($fileNameReplace)); |
|
26 | 26 | fclose($fileCopy); |
27 | 27 | return $text; |
28 | 28 | } |
29 | 29 | |
30 | - private function modifyClassName(string $text,string $fileName):string { |
|
30 | + private function modifyClassName(string $text, string $fileName):string { |
|
31 | 31 | |
32 | - $lines = explode("\n",$text); |
|
32 | + $lines = explode("\n", $text); |
|
33 | 33 | $newLines = array(); |
34 | 34 | foreach ($lines as $line) { |
35 | - $newLines[] = preg_replace('/\s+/',' ',trim($line)); |
|
35 | + $newLines[] = preg_replace('/\s+/', ' ', trim($line)); |
|
36 | 36 | } |
37 | - $searchValue = array_search("class ModelFile",$newLines); |
|
37 | + $searchValue = array_search("class ModelFile", $newLines); |
|
38 | 38 | $fileName = ucfirst($fileName); |
39 | 39 | $newLines[$searchValue] = "class $fileName"; |
40 | - return implode("\n",$newLines); |
|
40 | + return implode("\n", $newLines); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -7,9 +7,13 @@ |
||
7 | 7 | |
8 | 8 | |
9 | 9 | public function createFile(string $fileName){ |
10 | - if(!file_exists(CONFIG_PATH)) mkdir(CONFIG_PATH,0777,true); |
|
10 | + if(!file_exists(CONFIG_PATH)) { |
|
11 | + mkdir(CONFIG_PATH,0777,true); |
|
12 | + } |
|
11 | 13 | $fileName = ucfirst($fileName); |
12 | - if(file_exists(CONFIG_PATH ."/" .$fileName . ".php")) throw new \Exception("Arquivo ja existe"); |
|
14 | + if(file_exists(CONFIG_PATH ."/" .$fileName . ".php")) { |
|
15 | + throw new \Exception("Arquivo ja existe"); |
|
16 | + } |
|
13 | 17 | $file = fopen(CONFIG_PATH . "/" . $fileName . ".php",'w+'); |
14 | 18 | if($file){ |
15 | 19 | $text = $this->copyFile(); |
@@ -24,7 +24,7 @@ |
||
24 | 24 | foreach ($dir as $test) { |
25 | 25 | $array = explode('\\', $test); |
26 | 26 | foreach ($array as $value) { |
27 | - $model = $this->formatNameToObject($value); |
|
27 | + $model = $this->formatNameToObject($value); |
|
28 | 28 | $this->class_exists($model, $value); |
29 | 29 | } |
30 | 30 | } |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | |
4 | -define("CONFIG_PATH",$_SERVER["PWD"] . "/database/migrations"); |
|
5 | -define("PATH_CONFIG_DB",$_SERVER["PWD"] . "/db.php"); |
|
4 | +define("CONFIG_PATH", $_SERVER["PWD"] . "/database/migrations"); |
|
5 | +define("PATH_CONFIG_DB", $_SERVER["PWD"] . "/db.php"); |
|
6 | 6 | |
7 | -define("DB_HOST","127.0.0.1"); |
|
8 | -define("DB_USER","root"); |
|
9 | -define("DB_NAME","project"); |
|
10 | -define("DB_PASSWD","root"); |
|
11 | -define("DB_OPTIONS",[ |
|
7 | +define("DB_HOST", "127.0.0.1"); |
|
8 | +define("DB_USER", "root"); |
|
9 | +define("DB_NAME", "project"); |
|
10 | +define("DB_PASSWD", "root"); |
|
11 | +define("DB_OPTIONS", [ |
|
12 | 12 | PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'", |
13 | 13 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
14 | 14 | PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, |
@@ -11,14 +11,14 @@ discard block |
||
11 | 11 | |
12 | 12 | public function createRow(): string |
13 | 13 | { |
14 | - return preg_replace('/\s+/',' ',trim($this->query)); |
|
14 | + return preg_replace('/\s+/', ' ', trim($this->query)); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | public function id($type = "int"): static |
18 | 18 | { |
19 | - if($type == "int"){ |
|
19 | + if ($type == "int") { |
|
20 | 20 | $this->integer('id')->unsigned()->notNull()->primaryKey(); |
21 | - }else{ |
|
21 | + } else { |
|
22 | 22 | $this->bigint('id')->unsigned()->notNull()->primaryKey(); |
23 | 23 | } |
24 | 24 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | return $this; |
32 | 32 | } |
33 | 33 | |
34 | - public function string(string $name,int $limit = 255): static |
|
34 | + public function string(string $name, int $limit = 255): static |
|
35 | 35 | { |
36 | 36 | $this->query = "`$name` varchar(" . $limit . ")"; |
37 | 37 | return $this; |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | |
46 | 46 | public function timestamp(string $name): static |
47 | 47 | { |
48 | - $this->query = "`$name` timestamp"; |
|
48 | + $this->query = "`$name` timestamp"; |
|
49 | 49 | return $this; |
50 | 50 | } |
51 | 51 | |
52 | 52 | public function bigInt(string $name): static |
53 | 53 | { |
54 | - $this->query = "`$name` bigInt"; |
|
54 | + $this->query = "`$name` bigInt"; |
|
55 | 55 | return $this; |
56 | 56 | } |
57 | 57 | |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | public function foreignKey(string $name): static |
105 | 105 | { |
106 | 106 | $rand = rand(); |
107 | - $constrain = "CONSTRAINT `".$name ."_foreignKey_" .$rand . "` "; |
|
107 | + $constrain = "CONSTRAINT `" . $name . "_foreignKey_" . $rand . "` "; |
|
108 | 108 | $foreignKey = "FOREIGN KEY (`" . $name . "`)"; |
109 | 109 | $this->query = $constrain . $foreignKey; |
110 | 110 | return $this; |
111 | 111 | } |
112 | 112 | |
113 | - public function references(string $name,string $row = 'id'): static |
|
113 | + public function references(string $name, string $row = 'id'): static |
|
114 | 114 | { |
115 | 115 | $this->query .= " REFERENCES `$name` (`$row`)"; |
116 | 116 | return $this; |
@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | if($type == "int"){ |
20 | 20 | $this->integer('id')->unsigned()->notNull()->primaryKey(); |
21 | - }else{ |
|
21 | + } else{ |
|
22 | 22 | $this->bigint('id')->unsigned()->notNull()->primaryKey(); |
23 | 23 | } |
24 | 24 |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | try { |
39 | 39 | $config->createFile($_SERVER['argv'][2]); |
40 | 40 | fwrite(STDERR, |
41 | - 'File created successfully, in just databasee'. PHP_EOL |
|
41 | + 'File created successfully, in just databasee' . PHP_EOL |
|
42 | 42 | ); |
43 | 43 | } catch (Exception $e) { |
44 | 44 | fwrite(STDERR, |
45 | - $e->getMessage(). PHP_EOL |
|
45 | + $e->getMessage() . PHP_EOL |
|
46 | 46 | ); |
47 | 47 | |
48 | 48 | } |
49 | 49 | } else { |
50 | 50 | fwrite(STDERR, |
51 | - 'no parameters were passed'. PHP_EOL |
|
51 | + 'no parameters were passed' . PHP_EOL |
|
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | break; |
71 | 71 | } |
72 | 72 | default: |
73 | - print( "error\n"); |
|
73 | + print("error\n"); |
|
74 | 74 | break; |
75 | 75 | } |
76 | 76 |