22
33namespace Cheesegrits \Iseed ;
44
5+ use Cheesegrits \Iseed \Exceptions \TableNotFoundException ;
56use Illuminate \Filesystem \Filesystem ;
67use Illuminate \Support \Composer ;
7- use src \TableNotFoundException ;
88
99class Iseed
1010{
@@ -39,13 +39,15 @@ class Iseed
3939 */
4040 private $ composer ;
4141
42+ private $ files ;
43+
4244 /**
4345 * Constructs a new instance.
4446 *
4547 * @param \Illuminate\Filesystem\Filesystem|bool $filesystem Filesystem
46- * @param \Illuminate\Support\Composer|bool $composer Composer
48+ * @param \Illuminate\Support\Composer|bool $composer Composer
4749 */
48- public function __construct (Filesystem $ filesystem= null , Composer $ composer= null )
50+ public function __construct (Filesystem $ filesystem = null , Composer $ composer = null )
4951 {
5052 $ this ->files = $ filesystem ?: new Filesystem ;
5153 $ this ->composer = $ composer ?: new Composer ($ this ->files );
@@ -67,39 +69,40 @@ public function readStubFile($file)
6769 /**
6870 * Generates a seed file.
6971 *
70- * @param string $table Table name
71- * @param string $prefix Seeder class prefix
72- * @param string $suffix Seeder class suffix
73- * @param string $database Database connection name
74- * @param int $max Maximum seeded entries
75- * @param int $chunkSize Size of data chunks
76- * @param string $exclude Columns to exclude
77- * @param string $prerunEvent Prerun event name
72+ * @param string $table Table name
73+ * @param string $prefix Seeder class prefix
74+ * @param string $suffix Seeder class suffix
75+ * @param string $database Database connection name
76+ * @param int $max Maximum seeded entries
77+ * @param int $chunkSize Size of data chunks
78+ * @param string $exclude Columns to exclude
79+ * @param string $prerunEvent Prerun event name
7880 * @param string $postrunEvent Postrun event name
79- * @param bool $dumpAuto Composer auto-dump
80- * @param bool $indexed Indexed array
81- * @param int $orderBy Column to order by
82- * @param string $direction Default sort order
81+ * @param bool $dumpAuto Composer auto-dump
82+ * @param bool $indexed Indexed array
83+ * @param int $orderBy Column to order by
84+ * @param string $direction Default sort order
8385 *
86+ * @return void
8487 * @throws Cheesegrits\Iseed\TableNotFoundException
8588 *
86- * @return void
8789 */
8890 public function generateSeed (
8991 $ table ,
90- $ prefix =null ,
91- $ suffix =null ,
92- $ database =null ,
93- $ max =0 ,
94- $ chunkSize =0 ,
95- $ exclude =null ,
96- $ prerunEvent =null ,
97- $ postrunEvent =null ,
98- $ dumpAuto =true ,
99- $ indexed =true ,
100- $ orderBy =null ,
101- $ direction ='ASC '
102- ) {
92+ $ prefix = null ,
93+ $ suffix = null ,
94+ $ database = null ,
95+ $ max = 0 ,
96+ $ chunkSize = 0 ,
97+ $ exclude = null ,
98+ $ prerunEvent = null ,
99+ $ postrunEvent = null ,
100+ $ dumpAuto = true ,
101+ $ indexed = true ,
102+ $ orderBy = null ,
103+ $ direction = 'ASC '
104+ )
105+ {
103106 if (!$ database ) {
104107 $ database = config ('database.default ' );
105108 }
@@ -125,8 +128,8 @@ public function generateSeed(
125128 \File::exists (
126129 config ('iseed.stub_path ' )
127130 ) ?
128- config ('iseed.stub_path ' ) :
129- $ this ->getStubPath () . '/seed.stub '
131+ config ('iseed.stub_path ' ) :
132+ $ this ->getStubPath () . '/seed.stub '
130133 );
131134
132135 // Get a seed folder path
@@ -172,15 +175,15 @@ public function getSeedPath()
172175 /**
173176 * Get the Data
174177 *
175- * @param string $table Table name
176- * @param int $max Maximum seeded entries
177- * @param string $exclude Columns to exclude
178- * @param int $orderBy Column to order by
178+ * @param string $table Table name
179+ * @param int $max Maximum seeded entries
180+ * @param string $exclude Columns to exclude
181+ * @param int $orderBy Column to order by
179182 * @param string $direction Default sort order
180183 *
181184 * @return array
182185 */
183- public function getData ($ table , $ max , $ exclude= null , $ orderBy= null , $ direction= 'ASC ' )
186+ public function getData ($ table , $ max , $ exclude = null , $ orderBy = null , $ direction = 'ASC ' )
184187 {
185188 $ result = \DB ::connection ($ this ->databaseName )->table ($ table );
186189
@@ -242,13 +245,13 @@ public function hasTable($table)
242245 /**
243246 * Generates a seed class name (also used as a filename)
244247 *
245- * @param string $table Table name
248+ * @param string $table Table name
246249 * @param string $prefix Seeder class prefix
247250 * @param string $suffix Seeder class suffix
248251 *
249252 * @return string
250253 */
251- public function generateClassName ($ table , $ prefix= null , $ suffix= null )
254+ public function generateClassName ($ table , $ prefix = null , $ suffix = null )
252255 {
253256 $ tableString = '' ;
254257 $ tableName = explode ('_ ' , $ table );
@@ -271,14 +274,14 @@ public function getStubPath()
271274 /**
272275 * Populate the place-holders in the seed stub.
273276 *
274- * @param string $class Class name
275- * @param string $stub Stub name
276- * @param string $table Table name
277- * @param string $data Data object
278- * @param int $chunkSize Size of data chunks
279- * @param string $prerunEvent Prerun event name
277+ * @param string $class Class name
278+ * @param string $stub Stub name
279+ * @param string $table Table name
280+ * @param string $data Data object
281+ * @param int $chunkSize Size of data chunks
282+ * @param string $prerunEvent Prerun event name
280283 * @param string $postrunEvent Postrun event name
281- * @param bool $indexed Indexed array
284+ * @param bool $indexed Indexed array
282285 *
283286 * @return string
284287 */
@@ -291,7 +294,8 @@ public function populateStub(
291294 $ prerunEvent = null ,
292295 $ postrunEvent = null ,
293296 $ indexed = true
294- ) {
297+ )
298+ {
295299 $ chunkSize = $ chunkSize ?: config ('iseed.chunk_size ' );
296300
297301 $ inserts = '' ;
@@ -307,7 +311,7 @@ public function populateStub(
307311 }
308312
309313 $ namespace = implode ('\\' , array_filter (array_map ('ucfirst ' , explode ('/ ' , config ('iseed.path ' )))));
310- $ stub = str_replace ('{{ namespace }} ' , $ namespace , $ stub );
314+ $ stub = str_replace ('{{ namespace }} ' , $ namespace , $ stub );
311315 $ stub = str_replace ('{{ class }} ' , $ class , $ stub );
312316
313317 $ prerunEventInsert = '' ;
@@ -375,7 +379,7 @@ public function getPath($name, $path)
375379 *
376380 * @return string
377381 */
378- protected function prettifyArray ($ array , $ indexed= true )
382+ protected function prettifyArray ($ array , $ indexed = true )
379383 {
380384 $ content = ($ indexed )
381385 ? var_export ($ array , true )
@@ -426,8 +430,8 @@ protected function prettifyArray($array, $indexed=true)
426430 /**
427431 * Adds new lines to the passed content variable reference.
428432 *
429- * @param string $content Passed content
430- * @param int $numberOfLines Number of new lines
433+ * @param string $content Passed content
434+ * @param int $numberOfLines Number of new lines
431435 *
432436 * @return void
433437 */
@@ -442,8 +446,8 @@ private function addNewLines(&$content, $numberOfLines = 1)
442446 /**
443447 * Adds indentation to the passed content reference.
444448 *
445- * @param string $content Passed content
446- * @param int $numberOfIndents Number of indents
449+ * @param string $content Passed content
450+ * @param int $numberOfIndents Number of indents
447451 *
448452 * @return void
449453 */
@@ -478,9 +482,9 @@ public function cleanSection()
478482 *
479483 * @param string $className Database seeder class name
480484 *
485+ * @return bool
481486 * @link https://github.com/JeffreyWay/Laravel-4-Generators Kudoz to this package
482487 *
483- * @return bool
484488 */
485489 public function updateDatabaseSeederRunMethod ($ className )
486490 {
0 commit comments