Completed
Push — master ( bce893...4ab2af )
by Mark
06:22 queued 02:57
created
src/Migrator.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
             return [];
29 29
         }
30 30
 
31
-        $files = array_map(function ($file) {
31
+        $files = array_map(function($file) {
32 32
             return str_replace('.php', '', basename($file));
33 33
 
34 34
         }, $files);
Please login to merge, or discard this patch.
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -6,166 +6,166 @@
 block discarded – undo
6 6
 
7 7
 class Migrator extends M
8 8
 {
9
-    /**
10
-     * Fully qualified path to the application's migration directory.
11
-     *
12
-     * @var string
13
-     */
14
-    private $path;
15
-
16
-    /**
17
-     * Get all of the migration files in a given path.
18
-     *
19
-     * @param string $path
20
-     * @param bool   $recursive
21
-     *
22
-     * @return array
23
-     */
24
-    public function getMigrationFiles($path, $recursive = true)
25
-    {
26
-        $this->setPath($path);
27
-
28
-        if ($recursive === true) {
29
-            $files = $this->rglob($this->path.'/*_*.php', 0, true);
30
-        } else {
31
-            $files = $this->files->glob($this->path.'/*_*.php');
32
-        }
33
-
34
-        // Once we have the array of files in the directory we will just remove the
35
-        // extension and take the basename of the file which is all we need when
36
-        // finding the migrations that haven't been run against the databases.
37
-        if ($files === false) {
38
-            return [];
39
-        }
40
-
41
-        $files = array_map(function ($file) {
42
-            return str_replace('.php', '', basename($file));
43
-        }, $files);
44
-
45
-        // Once we have all of the formatted file names we will sort them and since
46
-        // they all start with a timestamp this should give us the migrations in
47
-        // the order they were actually created by the application developers.
48
-        sort($files);
49
-
50
-        return $files;
51
-    }
52
-
53
-    /**
54
-     * Require in all the migration files in a given path.
55
-     *
56
-     * @param array  $files
57
-     *
58
-     * @return void
59
-     */
60
-    public function requireFiles(array $files)
61
-    {
62
-        foreach ($files as $file) {
63
-            $newPath = $this->getFilePathWithFolders($file).'.php';
64
-            $this->files->requireOnce($newPath);
65
-        }
66
-    }
67
-
68
-    /**
69
-     * Run "up" a migration instance.
70
-     *
71
-     * @param string $file
72
-     * @param int    $batch
73
-     * @param bool   $pretend
74
-     *
75
-     * @return void
76
-     */
77
-    protected function runUp($file, $batch, $pretend)
78
-    {
79
-        // First we will resolve a "real" instance of the migration class from this
80
-        // migration file name. Once we have the instances we can run the actual
81
-        // command such as "up" or "down", or we can just simulate the action.
82
-        $migration = $this->resolve($file);
83
-
84
-        if ($pretend) {
85
-            return $this->pretendToRun($migration, 'up');
86
-        }
87
-
88
-        $migration->up();
89
-
90
-        // Once we have run a migrations class, we will log that it was run in this
91
-        // repository so that we don't try to run it next time we do a migration
92
-        // in the application. A migration repository keeps the migrate order.
93
-        $this->repository->log($this->getFilePathWithoutFolders($file), $batch);
94
-
95
-        $this->note("<info>Migrated:</info> $file");
96
-    }
97
-
98
-    /**
99
-     * Recursive glob.
100
-     *
101
-     * @param string $pattern
102
-     * @param int    $flags
103
-     * @param bool   $ignore
104
-     *
105
-     * @return array
106
-     */
107
-    public function rglob($pattern, $flags = 0, $ignore = false)
108
-    {
109
-        if ($ignore === false) {
110
-            $files = glob($pattern, $flags);
111
-        } else {
112
-            $files = [];
113
-        }
114
-
115
-        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
116
-            $files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags));
117
-        }
118
-
119
-        return $files;
120
-    }
121
-
122
-    /**
123
-     * Get the migration file path with our injected date folder.
124
-     *
125
-     * @param string $file
126
-     *
127
-     * @return string
128
-     */
129
-    public function getFilePathWithFolders($file)
130
-    {
131
-        $datePath = $this->getDateFolderStructure($file);
132
-
133
-        return $this->path.'/'.$datePath.$file;
134
-    }
135
-
136
-    /**
137
-     * Remove folders from file path.
138
-     *
139
-     * @param string $file
140
-     *
141
-     * @return string
142
-     */
143
-    public function getFilePathWithoutFolders($file)
144
-    {
145
-        return basename($file);
146
-    }
147
-
148
-    /**
149
-     * Add date folders to migrations path.
150
-     *
151
-     * @param string $file
152
-     *
153
-     * @return string
154
-     */
155
-    public function getDateFolderStructure($file)
156
-    {
157
-        $parts = explode('_', $file);
158
-
159
-        return $parts[0].'/'.$parts[1].'/';
160
-    }
161
-
162
-    /**
163
-     * Set the path.
164
-     *
165
-     * @param array|string $path
166
-     */
167
-    private function setPath($path)
168
-    {
169
-        $this->path = is_array($path) ? $path[0] : $path;
170
-    }
9
+	/**
10
+	 * Fully qualified path to the application's migration directory.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	private $path;
15
+
16
+	/**
17
+	 * Get all of the migration files in a given path.
18
+	 *
19
+	 * @param string $path
20
+	 * @param bool   $recursive
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function getMigrationFiles($path, $recursive = true)
25
+	{
26
+		$this->setPath($path);
27
+
28
+		if ($recursive === true) {
29
+			$files = $this->rglob($this->path.'/*_*.php', 0, true);
30
+		} else {
31
+			$files = $this->files->glob($this->path.'/*_*.php');
32
+		}
33
+
34
+		// Once we have the array of files in the directory we will just remove the
35
+		// extension and take the basename of the file which is all we need when
36
+		// finding the migrations that haven't been run against the databases.
37
+		if ($files === false) {
38
+			return [];
39
+		}
40
+
41
+		$files = array_map(function ($file) {
42
+			return str_replace('.php', '', basename($file));
43
+		}, $files);
44
+
45
+		// Once we have all of the formatted file names we will sort them and since
46
+		// they all start with a timestamp this should give us the migrations in
47
+		// the order they were actually created by the application developers.
48
+		sort($files);
49
+
50
+		return $files;
51
+	}
52
+
53
+	/**
54
+	 * Require in all the migration files in a given path.
55
+	 *
56
+	 * @param array  $files
57
+	 *
58
+	 * @return void
59
+	 */
60
+	public function requireFiles(array $files)
61
+	{
62
+		foreach ($files as $file) {
63
+			$newPath = $this->getFilePathWithFolders($file).'.php';
64
+			$this->files->requireOnce($newPath);
65
+		}
66
+	}
67
+
68
+	/**
69
+	 * Run "up" a migration instance.
70
+	 *
71
+	 * @param string $file
72
+	 * @param int    $batch
73
+	 * @param bool   $pretend
74
+	 *
75
+	 * @return void
76
+	 */
77
+	protected function runUp($file, $batch, $pretend)
78
+	{
79
+		// First we will resolve a "real" instance of the migration class from this
80
+		// migration file name. Once we have the instances we can run the actual
81
+		// command such as "up" or "down", or we can just simulate the action.
82
+		$migration = $this->resolve($file);
83
+
84
+		if ($pretend) {
85
+			return $this->pretendToRun($migration, 'up');
86
+		}
87
+
88
+		$migration->up();
89
+
90
+		// Once we have run a migrations class, we will log that it was run in this
91
+		// repository so that we don't try to run it next time we do a migration
92
+		// in the application. A migration repository keeps the migrate order.
93
+		$this->repository->log($this->getFilePathWithoutFolders($file), $batch);
94
+
95
+		$this->note("<info>Migrated:</info> $file");
96
+	}
97
+
98
+	/**
99
+	 * Recursive glob.
100
+	 *
101
+	 * @param string $pattern
102
+	 * @param int    $flags
103
+	 * @param bool   $ignore
104
+	 *
105
+	 * @return array
106
+	 */
107
+	public function rglob($pattern, $flags = 0, $ignore = false)
108
+	{
109
+		if ($ignore === false) {
110
+			$files = glob($pattern, $flags);
111
+		} else {
112
+			$files = [];
113
+		}
114
+
115
+		foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
116
+			$files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags));
117
+		}
118
+
119
+		return $files;
120
+	}
121
+
122
+	/**
123
+	 * Get the migration file path with our injected date folder.
124
+	 *
125
+	 * @param string $file
126
+	 *
127
+	 * @return string
128
+	 */
129
+	public function getFilePathWithFolders($file)
130
+	{
131
+		$datePath = $this->getDateFolderStructure($file);
132
+
133
+		return $this->path.'/'.$datePath.$file;
134
+	}
135
+
136
+	/**
137
+	 * Remove folders from file path.
138
+	 *
139
+	 * @param string $file
140
+	 *
141
+	 * @return string
142
+	 */
143
+	public function getFilePathWithoutFolders($file)
144
+	{
145
+		return basename($file);
146
+	}
147
+
148
+	/**
149
+	 * Add date folders to migrations path.
150
+	 *
151
+	 * @param string $file
152
+	 *
153
+	 * @return string
154
+	 */
155
+	public function getDateFolderStructure($file)
156
+	{
157
+		$parts = explode('_', $file);
158
+
159
+		return $parts[0].'/'.$parts[1].'/';
160
+	}
161
+
162
+	/**
163
+	 * Set the path.
164
+	 *
165
+	 * @param array|string $path
166
+	 */
167
+	private function setPath($path)
168
+	{
169
+		$this->path = is_array($path) ? $path[0] : $path;
170
+	}
171 171
 }
Please login to merge, or discard this patch.