@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param array $columns Columns to retrieve with the object. |
| 19 | 19 | * @return mixed Model|NULL An Eloquent object when there is a result, NULL when there are no matches. |
| 20 | 20 | */ |
| 21 | - public function findOneBy( $value = NULL, $field = 'id', array $columns = ['*'] ); |
|
| 21 | + public function findOneBy($value = NULL, $field = 'id', array $columns = ['*']); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * Finds ALL items the repository abstract without any kind of filter. |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * @param array $columns Columns to retrieve with the objects. |
| 27 | 27 | * @return mixed Collection Laravel Eloquent's Collection that may or may not be empty. |
| 28 | 28 | */ |
| 29 | - public function findAll( array $columns = ['*'] ); |
|
| 29 | + public function findAll(array $columns = ['*']); |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Finds ALL items by the provided field. If NULL specified for the first 2 parameters, then it will take ONLY the |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param array $columns Columns to retrieve with the objects. |
| 38 | 38 | * @return mixed Collection Laravel Eloquent's Collection that may or may not be empty. |
| 39 | 39 | */ |
| 40 | - public function findAllBy( $value = NULL, $field = NULL, array $columns = ['*'] ); |
|
| 40 | + public function findAllBy($value = NULL, $field = NULL, array $columns = ['*']); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Finds ALL the items in the repository where the given field is inside the given values. |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @param array $columns Columns to retrieve with the objects. |
| 48 | 48 | * @return mixed Collection Laravel Eloquent's Collection that may or may not be empty. |
| 49 | 49 | */ |
| 50 | - public function findAllWhereIn( array $value, $field, array $columns = ['*'] ); |
|
| 50 | + public function findAllWhereIn(array $value, $field, array $columns = ['*']); |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * Allows you to eager-load entity relationships when retrieving entities, either with or without criterias. |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @param array|string $relations Relations to eager-load along with the entities. |
| 56 | 56 | * @return mixed The current repository object instance. |
| 57 | 57 | */ |
| 58 | - public function with( $relations ); |
|
| 58 | + public function with($relations); |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Adds a criteria to the query. |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @param CriteriaInterface $criteria Object that declares and implements the criteria used. |
| 64 | 64 | * @return mixed The current repository object instance. |
| 65 | 65 | */ |
| 66 | - public function addCriteria( CriteriaInterface $criteria ); |
|
| 66 | + public function addCriteria(CriteriaInterface $criteria); |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * Skips the current criteria (all of them). Useful when you don't want to reset the object but just not use the |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param bool|TRUE $status If you want to skip the criteria or not. |
| 73 | 73 | * @return mixed The current repository object instance. |
| 74 | 74 | */ |
| 75 | - public function skipCriteria( $status = TRUE ); |
|
| 75 | + public function skipCriteria($status = TRUE); |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * Returns a Paginator that based on the criteria or filters given. |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * @param array $columns Columns to retrieve with the objects. |
| 82 | 82 | * @return Paginator object with the results and the paginator. |
| 83 | 83 | */ |
| 84 | - public function paginate( $perPage, array $columns = ['*'] ); |
|
| 84 | + public function paginate($perPage, array $columns = ['*']); |
|
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * Allows you to set the current page with using the paginator. Useful when you want to overwrite the $_GET['page'] |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @param int $page The page you want to retrieve. |
| 91 | 91 | * @return mixed The current repository object instance. |
| 92 | 92 | */ |
| 93 | - public function setCurrentPage( $page ); |
|
| 93 | + public function setCurrentPage($page); |
|
| 94 | 94 | |
| 95 | 95 | /** |
| 96 | 96 | * Creates a new entity of the entity type the repository handles, given certain data. |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param array $data Data the entity will have. |
| 99 | 99 | * @return mixed Model|NULL An Eloquent object when the entity was created, NULL in case of error. |
| 100 | 100 | */ |
| 101 | - public function create( array $data ); |
|
| 101 | + public function create(array $data); |
|
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Updates as many entities as the filter matches with the given $data. |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return mixed Model|NULL|integer An Eloquent object representing the updated entity, a number of entities updated if mass updating, |
| 110 | 110 | * or NULL in case of error. |
| 111 | 111 | */ |
| 112 | - public function updateBy( array $data, $value = NULL, $field = 'id' ); |
|
| 112 | + public function updateBy(array $data, $value = NULL, $field = 'id'); |
|
| 113 | 113 | |
| 114 | 114 | /** |
| 115 | 115 | * Removes as many entities as the filter matches. If softdelete is applied, then they will be soft-deleted. |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param string $field Field on the database that you will filter by. Default: id. |
| 121 | 121 | * @return boolean TRUE It will always return TRUE. |
| 122 | 122 | */ |
| 123 | - public function delete( $value = NULL, $field = 'id' ); |
|
| 123 | + public function delete($value = NULL, $field = 'id'); |
|
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * @return int number of records matching the criteria (or total amount of records). |
@@ -143,6 +143,6 @@ discard block |
||
| 143 | 143 | * @param string $field Field on the database that you will filter by. |
| 144 | 144 | * @return mixed |
| 145 | 145 | */ |
| 146 | - public function destroy( $value = NULL, $field = 'id' ); |
|
| 146 | + public function destroy($value = NULL, $field = 'id'); |
|
| 147 | 147 | |
| 148 | 148 | } |
| 149 | 149 | \ No newline at end of file |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | { |
| 32 | 32 | // merge default config |
| 33 | 33 | $this->mergeConfigFrom( |
| 34 | - __DIR__.$this->configPath , 'repositories' |
|
| 34 | + __DIR__.$this->configPath, 'repositories' |
|
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | 37 | // Bind the repositories. |
@@ -49,27 +49,27 @@ discard block |
||
| 49 | 49 | private function autoBindRepositories() |
| 50 | 50 | { |
| 51 | 51 | // Load config parameters needed. |
| 52 | - $repositoriesBasePath = config( 'repositories.repositories_path' ); |
|
| 53 | - $baseNamespace = rtrim( config( 'repositories.repository_interfaces_namespace' ), '\\' ) . '\\'; |
|
| 54 | - $skipRepositories = config( 'repositories.skip' ); |
|
| 55 | - $implementationBindings = config( 'repositories.bindings' ); |
|
| 56 | - $implementation = $this->findDefaultImplementation( $implementationBindings ); |
|
| 52 | + $repositoriesBasePath = config('repositories.repositories_path'); |
|
| 53 | + $baseNamespace = rtrim(config('repositories.repository_interfaces_namespace'), '\\').'\\'; |
|
| 54 | + $skipRepositories = config('repositories.skip'); |
|
| 55 | + $implementationBindings = config('repositories.bindings'); |
|
| 56 | + $implementation = $this->findDefaultImplementation($implementationBindings); |
|
| 57 | 57 | |
| 58 | - $allRepos = \File::files( $repositoriesBasePath ); |
|
| 58 | + $allRepos = \File::files($repositoriesBasePath); |
|
| 59 | 59 | |
| 60 | - foreach( $allRepos as $repo ) |
|
| 60 | + foreach ($allRepos as $repo) |
|
| 61 | 61 | { |
| 62 | - $interfaceName = pathinfo( $repo, PATHINFO_FILENAME ); |
|
| 63 | - if ( in_array( $interfaceName, $skipRepositories ) ) continue; |
|
| 62 | + $interfaceName = pathinfo($repo, PATHINFO_FILENAME); |
|
| 63 | + if (in_array($interfaceName, $skipRepositories)) continue; |
|
| 64 | 64 | else |
| 65 | 65 | { |
| 66 | - $commonName = str_replace( 'Interface', '', $interfaceName ); |
|
| 66 | + $commonName = str_replace('Interface', '', $interfaceName); |
|
| 67 | 67 | $interfaceFullClassName = $baseNamespace.$interfaceName; |
| 68 | 68 | |
| 69 | - foreach( $implementationBindings as $engine => $bindRepositories ) |
|
| 69 | + foreach ($implementationBindings as $engine => $bindRepositories) |
|
| 70 | 70 | { |
| 71 | - if ( $bindRepositories === 'default' ) continue; |
|
| 72 | - else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 71 | + if ($bindRepositories === 'default') continue; |
|
| 72 | + else if (in_array($interfaceName, $bindRepositories)) |
|
| 73 | 73 | { |
| 74 | 74 | $implementation = $engine; |
| 75 | 75 | break; |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | $fullClassName = $baseNamespace.$implementation.'\\'.$commonName; |
| 80 | 80 | |
| 81 | - if ( class_exists( $fullClassName ) ) |
|
| 81 | + if (class_exists($fullClassName)) |
|
| 82 | 82 | { |
| 83 | 83 | // Bind the class. |
| 84 | - $this->app->bind( $interfaceFullClassName, function ( $app ) use ( $fullClassName ) |
|
| 84 | + $this->app->bind($interfaceFullClassName, function($app) use ($fullClassName) |
|
| 85 | 85 | { |
| 86 | - return $app->make( $fullClassName ); |
|
| 86 | + return $app->make($fullClassName); |
|
| 87 | 87 | }); |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | * @param $implementations |
| 95 | 95 | * @return array|mixed|string |
| 96 | 96 | */ |
| 97 | - private function findDefaultImplementation( $implementations ) |
|
| 97 | + private function findDefaultImplementation($implementations) |
|
| 98 | 98 | { |
| 99 | - $filtered = array_filter( $implementations, function( $k ) { |
|
| 99 | + $filtered = array_filter($implementations, function($k) { |
|
| 100 | 100 | return $k === 'default'; |
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | 103 | $default = array_keys($filtered); |
| 104 | - $default = is_array( $default ) ? $default[0] : $default; |
|
| 104 | + $default = is_array($default) ? $default[0] : $default; |
|
| 105 | 105 | |
| 106 | 106 | return $default ? $default : 'eloquent'; |
| 107 | 107 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | private function registerRepositoryGenerator() |
| 113 | 113 | { |
| 114 | - $this->app->singleton('command.repository', function ($app) |
|
| 114 | + $this->app->singleton('command.repository', function($app) |
|
| 115 | 115 | { |
| 116 | 116 | return $app['OkayBueno\Repositories\Commands\MakeRepositoryCommand']; |
| 117 | 117 | }); |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | private function registerCriteriaGenerator() |
| 127 | 127 | { |
| 128 | - $this->app->singleton('command.criteria', function ($app) |
|
| 128 | + $this->app->singleton('command.criteria', function($app) |
|
| 129 | 129 | { |
| 130 | 130 | return $app['OkayBueno\Repositories\Commands\MakeCriteriaCommand']; |
| 131 | 131 | }); |
@@ -60,16 +60,18 @@ |
||
| 60 | 60 | foreach( $allRepos as $repo ) |
| 61 | 61 | { |
| 62 | 62 | $interfaceName = pathinfo( $repo, PATHINFO_FILENAME ); |
| 63 | - if ( in_array( $interfaceName, $skipRepositories ) ) continue; |
|
| 64 | - else |
|
| 63 | + if ( in_array( $interfaceName, $skipRepositories ) ) { |
|
| 64 | + continue; |
|
| 65 | + } else |
|
| 65 | 66 | { |
| 66 | 67 | $commonName = str_replace( 'Interface', '', $interfaceName ); |
| 67 | 68 | $interfaceFullClassName = $baseNamespace.$interfaceName; |
| 68 | 69 | |
| 69 | 70 | foreach( $implementationBindings as $engine => $bindRepositories ) |
| 70 | 71 | { |
| 71 | - if ( $bindRepositories === 'default' ) continue; |
|
| 72 | - else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 72 | + if ( $bindRepositories === 'default' ) { |
|
| 73 | + continue; |
|
| 74 | + } else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 73 | 75 | { |
| 74 | 76 | $implementation = $engine; |
| 75 | 77 | break; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param int $amount |
| 19 | 19 | * @return mixed |
| 20 | 20 | */ |
| 21 | - public function incrementCounter( Model $model, $counter, $amount = 1 ); |
|
| 21 | + public function incrementCounter(Model $model, $counter, $amount = 1); |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -31,5 +31,5 @@ discard block |
||
| 31 | 31 | * @param bool|FALSE $allowNegative |
| 32 | 32 | * @return mixed |
| 33 | 33 | */ |
| 34 | - public function decrementCounter( Model $model, $counter, $amount = 1, $allowNegative = FALSE ); |
|
| 34 | + public function decrementCounter(Model $model, $counter, $amount = 1, $allowNegative = FALSE); |
|
| 35 | 35 | } |
| 36 | 36 | \ No newline at end of file |
@@ -16,5 +16,5 @@ |
||
| 16 | 16 | * @param string $field Column in the DB used for the filter. |
| 17 | 17 | * @return void |
| 18 | 18 | */ |
| 19 | - public function restore( $value, $field = 'id' ); |
|
| 19 | + public function restore($value, $field = 'id'); |
|
| 20 | 20 | } |
| 21 | 21 | \ No newline at end of file |
@@ -30,15 +30,15 @@ discard block |
||
| 30 | 30 | public function fire() |
| 31 | 31 | { |
| 32 | 32 | $model = $this->argument('model'); |
| 33 | - $implementation = strtolower( $this->option('implementation') ); |
|
| 33 | + $implementation = strtolower($this->option('implementation')); |
|
| 34 | 34 | |
| 35 | - if ( class_exists( $model ) ) |
|
| 35 | + if (class_exists($model)) |
|
| 36 | 36 | { |
| 37 | - $supportedImplementations = array_keys( config( 'repositories.supported_implementations' ) ); |
|
| 37 | + $supportedImplementations = array_keys(config('repositories.supported_implementations')); |
|
| 38 | 38 | |
| 39 | - if ( $implementation ) |
|
| 39 | + if ($implementation) |
|
| 40 | 40 | { |
| 41 | - if ( !in_array( $implementation, $supportedImplementations ) ) |
|
| 41 | + if (!in_array($implementation, $supportedImplementations)) |
|
| 42 | 42 | { |
| 43 | 43 | $this->error("The implementation '$implementation' is not supported at this moment. Want me to provide support? Open an issue :)."); |
| 44 | 44 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Populate the properties with the right values. |
| 53 | - $this->populateValuesForProperties( $model, $implementation ); |
|
| 53 | + $this->populateValuesForProperties($model, $implementation); |
|
| 54 | 54 | |
| 55 | 55 | $this->createInterface(); |
| 56 | 56 | $this->createRepository(); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | } else |
| 63 | 63 | { |
| 64 | - $this->error( "The '$this->modelClassShortName' ('$this->modelClassNamespace\\$this->modelClassShortName') model does not exist. Please check that the namespace and the class name are valid."); |
|
| 64 | + $this->error("The '$this->modelClassShortName' ('$this->modelClassNamespace\\$this->modelClassShortName') model does not exist. Please check that the namespace and the class name are valid."); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | * @param $model |
| 70 | 70 | * @param $implementation |
| 71 | 71 | */ |
| 72 | - protected function populateValuesForProperties( $model, $implementation ) |
|
| 72 | + protected function populateValuesForProperties($model, $implementation) |
|
| 73 | 73 | { |
| 74 | - $modelClass = new \ReflectionClass( $model ); |
|
| 74 | + $modelClass = new \ReflectionClass($model); |
|
| 75 | 75 | |
| 76 | 76 | $this->implementation = $implementation; |
| 77 | 77 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | $this->repositoryClassName = $this->modelClassShortName.'Repository'; |
| 82 | 82 | $this->repositoryInterfaceName = $this->repositoryClassName.'Interface'; |
| 83 | 83 | |
| 84 | - $this->repositoryInterfaceNamespace = rtrim( config( 'repositories.repository_interfaces_namespace' ), '\\' ); |
|
| 85 | - $this->repositoryClassNamespace = $this->repositoryInterfaceNamespace.'\\'.ucfirst( $implementation ); |
|
| 84 | + $this->repositoryInterfaceNamespace = rtrim(config('repositories.repository_interfaces_namespace'), '\\'); |
|
| 85 | + $this->repositoryClassNamespace = $this->repositoryInterfaceNamespace.'\\'.ucfirst($implementation); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -90,17 +90,17 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | protected function createRepository() |
| 92 | 92 | { |
| 93 | - $basePath = config( 'repositories.repositories_path' ).'/'.ucfirst( $this->implementation ); |
|
| 93 | + $basePath = config('repositories.repositories_path').'/'.ucfirst($this->implementation); |
|
| 94 | 94 | |
| 95 | 95 | $classFilePath = $basePath.'/'.$this->repositoryClassName.'.php'; |
| 96 | 96 | |
| 97 | - $this->makeDirectory( $basePath ); |
|
| 97 | + $this->makeDirectory($basePath); |
|
| 98 | 98 | |
| 99 | - if ( !$this->filesystem->exists( $classFilePath ) ) |
|
| 99 | + if (!$this->filesystem->exists($classFilePath)) |
|
| 100 | 100 | { |
| 101 | 101 | // Read the stub and replace |
| 102 | - $this->filesystem->put( $classFilePath, $this->compileRepositoryStub() ); |
|
| 103 | - $this->info("'".ucfirst( $this->implementation )."' implementation created successfully for '$this->modelClassShortName'."); |
|
| 102 | + $this->filesystem->put($classFilePath, $this->compileRepositoryStub()); |
|
| 103 | + $this->info("'".ucfirst($this->implementation)."' implementation created successfully for '$this->modelClassShortName'."); |
|
| 104 | 104 | $this->composer->dumpAutoloads(); |
| 105 | 105 | } else |
| 106 | 106 | { |
@@ -114,16 +114,16 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | protected function createInterface() |
| 116 | 116 | { |
| 117 | - $repositoriesBasePath = config( 'repositories.repositories_path' ); |
|
| 117 | + $repositoriesBasePath = config('repositories.repositories_path'); |
|
| 118 | 118 | |
| 119 | 119 | $interfaceFilePath = $repositoriesBasePath.'/'.$this->repositoryInterfaceName.'.php'; |
| 120 | 120 | |
| 121 | - $this->makeDirectory( $repositoriesBasePath ); |
|
| 121 | + $this->makeDirectory($repositoriesBasePath); |
|
| 122 | 122 | |
| 123 | - if ( !$this->filesystem->exists( $interfaceFilePath ) ) |
|
| 123 | + if (!$this->filesystem->exists($interfaceFilePath)) |
|
| 124 | 124 | { |
| 125 | 125 | // Read the stub and replace |
| 126 | - $this->filesystem->put( $interfaceFilePath, $this->compileRepositoryInterfaceStub() ); |
|
| 126 | + $this->filesystem->put($interfaceFilePath, $this->compileRepositoryInterfaceStub()); |
|
| 127 | 127 | $this->info("Interface created successfully for '$this->modelClassShortName'."); |
| 128 | 128 | $this->composer->dumpAutoloads(); |
| 129 | 129 | } else |
@@ -138,10 +138,10 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | protected function compileRepositoryInterfaceStub() |
| 140 | 140 | { |
| 141 | - $stub = $this->filesystem->get(__DIR__ . '/../stubs/repository-interface.stub'); |
|
| 141 | + $stub = $this->filesystem->get(__DIR__.'/../stubs/repository-interface.stub'); |
|
| 142 | 142 | |
| 143 | - $stub = $this->replaceInterfaceNamespace( $stub ); |
|
| 144 | - $stub = $this->replaceInterfaceName( $stub ); |
|
| 143 | + $stub = $this->replaceInterfaceNamespace($stub); |
|
| 144 | + $stub = $this->replaceInterfaceName($stub); |
|
| 145 | 145 | |
| 146 | 146 | return $stub; |
| 147 | 147 | } |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | protected function compileRepositoryStub() |
| 153 | 153 | { |
| 154 | - $stub = $this->filesystem->get(__DIR__ . '/../stubs/repository.stub'); |
|
| 154 | + $stub = $this->filesystem->get(__DIR__.'/../stubs/repository.stub'); |
|
| 155 | 155 | |
| 156 | - $stub = $this->replaceInterfaceNamespace( $stub ); |
|
| 157 | - $stub = $this->replaceInterfaceName( $stub ); |
|
| 158 | - $stub = $this->replaceParentRepositoryClassNamespaceAndName( $stub ); |
|
| 159 | - $stub = $this->replaceRepositoryClassNamespaceAndName( $stub ); |
|
| 160 | - $stub = $this->replaceModelClassNamespaceAndName( $stub ); |
|
| 156 | + $stub = $this->replaceInterfaceNamespace($stub); |
|
| 157 | + $stub = $this->replaceInterfaceName($stub); |
|
| 158 | + $stub = $this->replaceParentRepositoryClassNamespaceAndName($stub); |
|
| 159 | + $stub = $this->replaceRepositoryClassNamespaceAndName($stub); |
|
| 160 | + $stub = $this->replaceModelClassNamespaceAndName($stub); |
|
| 161 | 161 | |
| 162 | 162 | return $stub; |
| 163 | 163 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param $stub |
| 167 | 167 | * @return $this |
| 168 | 168 | */ |
| 169 | - private function replaceInterfaceNamespace( $stub ) |
|
| 169 | + private function replaceInterfaceNamespace($stub) |
|
| 170 | 170 | { |
| 171 | 171 | return str_replace('{{repositoryInterfaceNamespace}}', $this->repositoryInterfaceNamespace, $stub); |
| 172 | 172 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * @param $stub |
| 176 | 176 | * @return mixed |
| 177 | 177 | */ |
| 178 | - private function replaceInterfaceName( $stub ) |
|
| 178 | + private function replaceInterfaceName($stub) |
|
| 179 | 179 | { |
| 180 | 180 | return str_replace('{{repositoryInterfaceName}}', $this->repositoryInterfaceName, $stub); |
| 181 | 181 | } |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | * @param $stub |
| 186 | 186 | * @return mixed |
| 187 | 187 | */ |
| 188 | - private function replaceParentRepositoryClassNamespaceAndName( $stub ) |
|
| 188 | + private function replaceParentRepositoryClassNamespaceAndName($stub) |
|
| 189 | 189 | { |
| 190 | - $implementations = config( 'repositories.supported_implementations' ); |
|
| 190 | + $implementations = config('repositories.supported_implementations'); |
|
| 191 | 191 | |
| 192 | - $parentClassImplementation = $implementations[ $this->implementation ]; |
|
| 192 | + $parentClassImplementation = $implementations[$this->implementation]; |
|
| 193 | 193 | |
| 194 | 194 | $reflex = new \ReflectionClass($parentClassImplementation); |
| 195 | 195 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @param $stub |
| 203 | 203 | * @return mixed |
| 204 | 204 | */ |
| 205 | - private function replaceRepositoryClassNamespaceAndName( $stub ) |
|
| 205 | + private function replaceRepositoryClassNamespaceAndName($stub) |
|
| 206 | 206 | { |
| 207 | 207 | $stub = str_replace('{{repositoryClassName}}', $this->repositoryClassName, $stub); |
| 208 | 208 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param $stub |
| 215 | 215 | * @return mixed |
| 216 | 216 | */ |
| 217 | - private function replaceModelClassNamespaceAndName( $stub ) |
|
| 217 | + private function replaceModelClassNamespaceAndName($stub) |
|
| 218 | 218 | { |
| 219 | 219 | $stub = str_replace('{{modelName}}', $this->modelClassShortName, $stub); |
| 220 | 220 | |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | public function fire() |
| 29 | 29 | { |
| 30 | 30 | $criteria = $this->argument('criteria'); |
| 31 | - $implementation = strtolower( $this->option('implementation') ); |
|
| 31 | + $implementation = strtolower($this->option('implementation')); |
|
| 32 | 32 | |
| 33 | - $this->populateValuesForProperties( $criteria, $implementation ); |
|
| 33 | + $this->populateValuesForProperties($criteria, $implementation); |
|
| 34 | 34 | $this->createCriteria(); |
| 35 | 35 | |
| 36 | 36 | $this->info('Generating autoload...'); |
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | * @param $criteria |
| 44 | 44 | * @param $implementation |
| 45 | 45 | */ |
| 46 | - protected function populateValuesForProperties( $criteria, $implementation ) |
|
| 46 | + protected function populateValuesForProperties($criteria, $implementation) |
|
| 47 | 47 | { |
| 48 | 48 | $this->implementation = $implementation ? $implementation : $this->findDefaultImplementation(); |
| 49 | 49 | |
| 50 | - $criteriaNameForFolder = str_replace('\\', '/', $criteria ); |
|
| 51 | - $this->criteriaFolder = ucfirst( $this->implementation ); |
|
| 50 | + $criteriaNameForFolder = str_replace('\\', '/', $criteria); |
|
| 51 | + $this->criteriaFolder = ucfirst($this->implementation); |
|
| 52 | 52 | |
| 53 | - $folder = pathinfo( $criteriaNameForFolder , PATHINFO_DIRNAME );; |
|
| 54 | - if ( $folder ) $this->criteriaFolder .= '/'.$folder; |
|
| 53 | + $folder = pathinfo($criteriaNameForFolder, PATHINFO_DIRNAME); ; |
|
| 54 | + if ($folder) $this->criteriaFolder .= '/'.$folder; |
|
| 55 | 55 | |
| 56 | - $this->criteriaClassName = pathinfo( $criteriaNameForFolder , PATHINFO_FILENAME ); |
|
| 57 | - $this->criteriaClassNamespace = rtrim( config( 'repositories.criterias_namespace' ), '\\' ) . '\\' . str_replace( '/', '\\', $this->criteriaFolder ); |
|
| 56 | + $this->criteriaClassName = pathinfo($criteriaNameForFolder, PATHINFO_FILENAME); |
|
| 57 | + $this->criteriaClassNamespace = rtrim(config('repositories.criterias_namespace'), '\\').'\\'.str_replace('/', '\\', $this->criteriaFolder); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -62,18 +62,18 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | protected function createCriteria() |
| 64 | 64 | { |
| 65 | - $basePath = config( 'repositories.criterias_path' ); |
|
| 65 | + $basePath = config('repositories.criterias_path'); |
|
| 66 | 66 | |
| 67 | - if ( $this->criteriaFolder ) $basePath .= '/'.$this->criteriaFolder; |
|
| 67 | + if ($this->criteriaFolder) $basePath .= '/'.$this->criteriaFolder; |
|
| 68 | 68 | |
| 69 | - $this->makeDirectory( $basePath ); |
|
| 69 | + $this->makeDirectory($basePath); |
|
| 70 | 70 | |
| 71 | - $criteriaFilePath = $basePath .'/'.$this->criteriaClassName.'.php'; |
|
| 71 | + $criteriaFilePath = $basePath.'/'.$this->criteriaClassName.'.php'; |
|
| 72 | 72 | |
| 73 | - if ( !$this->filesystem->exists( $criteriaFilePath ) ) |
|
| 73 | + if (!$this->filesystem->exists($criteriaFilePath)) |
|
| 74 | 74 | { |
| 75 | 75 | // Read the stub and replace |
| 76 | - $this->filesystem->put( $criteriaFilePath, $this->compileCriteriaStub() ); |
|
| 76 | + $this->filesystem->put($criteriaFilePath, $this->compileCriteriaStub()); |
|
| 77 | 77 | $this->info("Criteria '$this->criteriaClassName' created successfully in '$criteriaFilePath'."); |
| 78 | 78 | $this->composer->dumpAutoloads(); |
| 79 | 79 | } else |
@@ -88,10 +88,10 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | protected function compileCriteriaStub( ) |
| 90 | 90 | { |
| 91 | - $stub = $this->filesystem->get(__DIR__ . '/../stubs/eloquent-criteria.stub'); |
|
| 91 | + $stub = $this->filesystem->get(__DIR__.'/../stubs/eloquent-criteria.stub'); |
|
| 92 | 92 | |
| 93 | - $stub = $this->replaceCriteriaNamespace( $stub ); |
|
| 94 | - $stub = $this->replaceCriteriaName( $stub ); |
|
| 93 | + $stub = $this->replaceCriteriaNamespace($stub); |
|
| 94 | + $stub = $this->replaceCriteriaName($stub); |
|
| 95 | 95 | |
| 96 | 96 | return $stub; |
| 97 | 97 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param $stub |
| 102 | 102 | * @return mixed |
| 103 | 103 | */ |
| 104 | - private function replaceCriteriaNamespace( $stub ) |
|
| 104 | + private function replaceCriteriaNamespace($stub) |
|
| 105 | 105 | { |
| 106 | 106 | return str_replace('{{criteriaNamespace}}', $this->criteriaClassNamespace, $stub); |
| 107 | 107 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param $stub |
| 111 | 111 | * @return mixed |
| 112 | 112 | */ |
| 113 | - private function replaceCriteriaName( $stub ) |
|
| 113 | + private function replaceCriteriaName($stub) |
|
| 114 | 114 | { |
| 115 | 115 | return str_replace('{{criteriaClassName}}', $this->criteriaClassName, $stub); |
| 116 | 116 | } |
@@ -51,7 +51,9 @@ discard block |
||
| 51 | 51 | $this->criteriaFolder = ucfirst( $this->implementation ); |
| 52 | 52 | |
| 53 | 53 | $folder = pathinfo( $criteriaNameForFolder , PATHINFO_DIRNAME );; |
| 54 | - if ( $folder ) $this->criteriaFolder .= '/'.$folder; |
|
| 54 | + if ( $folder ) { |
|
| 55 | + $this->criteriaFolder .= '/'.$folder; |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | $this->criteriaClassName = pathinfo( $criteriaNameForFolder , PATHINFO_FILENAME ); |
| 57 | 59 | $this->criteriaClassNamespace = rtrim( config( 'repositories.criterias_namespace' ), '\\' ) . '\\' . str_replace( '/', '\\', $this->criteriaFolder ); |
@@ -64,7 +66,9 @@ discard block |
||
| 64 | 66 | { |
| 65 | 67 | $basePath = config( 'repositories.criterias_path' ); |
| 66 | 68 | |
| 67 | - if ( $this->criteriaFolder ) $basePath .= '/'.$this->criteriaFolder; |
|
| 69 | + if ( $this->criteriaFolder ) { |
|
| 70 | + $basePath .= '/'.$this->criteriaFolder; |
|
| 71 | + } |
|
| 68 | 72 | |
| 69 | 73 | $this->makeDirectory( $basePath ); |
| 70 | 74 | |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * @param $path |
| 33 | 33 | */ |
| 34 | - protected function makeDirectory( $path ) |
|
| 34 | + protected function makeDirectory($path) |
|
| 35 | 35 | { |
| 36 | - if ( !$this->filesystem->isDirectory( $path ) ) |
|
| 36 | + if (!$this->filesystem->isDirectory($path)) |
|
| 37 | 37 | { |
| 38 | - $this->filesystem->makeDirectory( $path, 0775, true, true); |
|
| 38 | + $this->filesystem->makeDirectory($path, 0775, true, true); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | protected function findDefaultImplementation() |
| 47 | 47 | { |
| 48 | - $implementationBindings = config( 'repositories.bindings' ); |
|
| 48 | + $implementationBindings = config('repositories.bindings'); |
|
| 49 | 49 | |
| 50 | - $filtered = array_filter( $implementationBindings, function( $k ) { |
|
| 50 | + $filtered = array_filter($implementationBindings, function($k) { |
|
| 51 | 51 | return $k === 'default'; |
| 52 | 52 | }); |
| 53 | 53 | |
| 54 | 54 | $default = array_keys($filtered); |
| 55 | - $default = is_array( $default ) ? $default[0] : $default; |
|
| 55 | + $default = is_array($default) ? $default[0] : $default; |
|
| 56 | 56 | |
| 57 | 57 | return $default ? $default : 'eloquent'; |
| 58 | 58 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | * @param int $amount |
| 18 | 18 | * @return Model |
| 19 | 19 | */ |
| 20 | - public function incrementCounter( Model $model, $counter, $amount = 1 ) |
|
| 20 | + public function incrementCounter(Model $model, $counter, $amount = 1) |
|
| 21 | 21 | { |
| 22 | - $amount = $this->getAmount( $amount ); |
|
| 22 | + $amount = $this->getAmount($amount); |
|
| 23 | 23 | |
| 24 | - if ( $amount ) $model->increment( $counter, $amount ); |
|
| 25 | - else $model->increment( $counter ); |
|
| 24 | + if ($amount) $model->increment($counter, $amount); |
|
| 25 | + else $model->increment($counter); |
|
| 26 | 26 | |
| 27 | 27 | return $model; |
| 28 | 28 | } |
@@ -35,22 +35,22 @@ discard block |
||
| 35 | 35 | * @param bool|FALSE $allowNegative |
| 36 | 36 | * @return Model |
| 37 | 37 | */ |
| 38 | - public function decrementCounter( Model $model, $counter, $amount = 1, $allowNegative = FALSE ) |
|
| 38 | + public function decrementCounter(Model $model, $counter, $amount = 1, $allowNegative = FALSE) |
|
| 39 | 39 | { |
| 40 | - $amount = $this->getAmount( $amount, 1 ); |
|
| 40 | + $amount = $this->getAmount($amount, 1); |
|
| 41 | 41 | |
| 42 | 42 | $currentValue = $model->{$counter}; |
| 43 | 43 | $final = $model->{$counter} - $amount; |
| 44 | 44 | |
| 45 | - if ( !$allowNegative ) |
|
| 45 | + if (!$allowNegative) |
|
| 46 | 46 | { |
| 47 | - if ( $currentValue && $final < 0 ) |
|
| 47 | + if ($currentValue && $final < 0) |
|
| 48 | 48 | { |
| 49 | 49 | $model->{$counter} = 0; |
| 50 | 50 | $model->save(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - } else $model->decrement( $counter, $amount ); |
|
| 53 | + } else $model->decrement($counter, $amount); |
|
| 54 | 54 | |
| 55 | 55 | return $model; |
| 56 | 56 | } |
@@ -61,8 +61,8 @@ discard block |
||
| 61 | 61 | * @param null $default |
| 62 | 62 | * @return int|null |
| 63 | 63 | */ |
| 64 | - private function getAmount( $amount, $default = NULL ) |
|
| 64 | + private function getAmount($amount, $default = NULL) |
|
| 65 | 65 | { |
| 66 | - return is_int( $amount ) && $amount > 1 ? $amount : $default; |
|
| 66 | + return is_int($amount) && $amount > 1 ? $amount : $default; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | \ No newline at end of file |
@@ -21,8 +21,11 @@ discard block |
||
| 21 | 21 | { |
| 22 | 22 | $amount = $this->getAmount( $amount ); |
| 23 | 23 | |
| 24 | - if ( $amount ) $model->increment( $counter, $amount ); |
|
| 25 | - else $model->increment( $counter ); |
|
| 24 | + if ( $amount ) { |
|
| 25 | + $model->increment( $counter, $amount ); |
|
| 26 | + } else { |
|
| 27 | + $model->increment( $counter ); |
|
| 28 | + } |
|
| 26 | 29 | |
| 27 | 30 | return $model; |
| 28 | 31 | } |
@@ -50,7 +53,9 @@ discard block |
||
| 50 | 53 | $model->save(); |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | - } else $model->decrement( $counter, $amount ); |
|
| 56 | + } else { |
|
| 57 | + $model->decrement( $counter, $amount ); |
|
| 58 | + } |
|
| 54 | 59 | |
| 55 | 60 | return $model; |
| 56 | 61 | } |
@@ -13,8 +13,8 @@ |
||
| 13 | 13 | * @param $value |
| 14 | 14 | * @param string $field |
| 15 | 15 | */ |
| 16 | - public function restore( $value, $field = 'id' ) |
|
| 16 | + public function restore($value, $field = 'id') |
|
| 17 | 17 | { |
| 18 | - $this->model->where( $field, $value )->restore(); |
|
| 18 | + $this->model->where($field, $value)->restore(); |
|
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | 21 | \ No newline at end of file |