@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | public function handle() |
| 29 | 29 | { |
| 30 | 30 | $model = $this->argument('model'); |
| 31 | - $implementation = strtolower( $this->option('implementation') ); |
|
| 31 | + $implementation = strtolower($this->option('implementation')); |
|
| 32 | 32 | |
| 33 | - if ( class_exists( $model ) ) |
|
| 33 | + if (class_exists($model)) |
|
| 34 | 34 | { |
| 35 | - $supportedImplementations = array_keys( config( 'repositories.supported_implementations' ) ); |
|
| 35 | + $supportedImplementations = array_keys(config('repositories.supported_implementations')); |
|
| 36 | 36 | |
| 37 | - if ( $implementation ) |
|
| 37 | + if ($implementation) |
|
| 38 | 38 | { |
| 39 | - if ( !in_array( $implementation, $supportedImplementations ) ) |
|
| 39 | + if (!in_array($implementation, $supportedImplementations)) |
|
| 40 | 40 | { |
| 41 | 41 | $this->error("The implementation '$implementation' is not supported at this moment. Want me to provide support? Open an issue :)."); |
| 42 | 42 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // Populate the properties with the right values. |
| 51 | - $this->populateValuesForProperties( $model, $implementation ); |
|
| 51 | + $this->populateValuesForProperties($model, $implementation); |
|
| 52 | 52 | |
| 53 | 53 | $this->createInterface(); |
| 54 | 54 | $this->createRepository(); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $this->error( "The '$model' model does not exist. Please check that the namespace and the class name are valid."); |
|
| 64 | + $this->error("The '$model' 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 | |
@@ -63,16 +63,18 @@ |
||
| 63 | 63 | { |
| 64 | 64 | $implementation = $defaultImplementation; |
| 65 | 65 | $interfaceName = pathinfo( $repo, PATHINFO_FILENAME ); |
| 66 | - if ( in_array( $interfaceName, $skipRepositories ) ) continue; |
|
| 67 | - else |
|
| 66 | + if ( in_array( $interfaceName, $skipRepositories ) ) { |
|
| 67 | + continue; |
|
| 68 | + } else |
|
| 68 | 69 | { |
| 69 | 70 | $commonName = str_replace( 'Interface', '', $interfaceName ); |
| 70 | 71 | $interfaceFullClassName = $baseNamespace.$interfaceName; |
| 71 | 72 | |
| 72 | 73 | foreach( $implementationBindings as $engine => $bindRepositories ) |
| 73 | 74 | { |
| 74 | - if ( $bindRepositories === 'default' ) continue; |
|
| 75 | - else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 75 | + if ( $bindRepositories === 'default' ) { |
|
| 76 | + continue; |
|
| 77 | + } else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 76 | 78 | { |
| 77 | 79 | $implementation = $engine; |
| 78 | 80 | break; |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | { |
| 33 | 33 | // merge default config |
| 34 | 34 | $this->mergeConfigFrom( |
| 35 | - __DIR__.$this->configPath , 'repositories' |
|
| 35 | + __DIR__.$this->configPath, 'repositories' |
|
| 36 | 36 | ); |
| 37 | 37 | |
| 38 | 38 | // Bind the repositories. |
@@ -50,44 +50,44 @@ discard block |
||
| 50 | 50 | private function autoBindRepositories() |
| 51 | 51 | { |
| 52 | 52 | // Load config parameters needed. |
| 53 | - $repositoriesBasePath = config( 'repositories.repositories_path' ); |
|
| 54 | - $baseNamespace = rtrim( config( 'repositories.repository_interfaces_namespace' ), '\\' ) . '\\'; |
|
| 55 | - $skipRepositories = config( 'repositories.skip' ); |
|
| 56 | - $implementationBindings = config( 'repositories.bindings' ); |
|
| 57 | - $defaultImplementation = $this->findDefaultImplementation( $implementationBindings ); |
|
| 53 | + $repositoriesBasePath = config('repositories.repositories_path'); |
|
| 54 | + $baseNamespace = rtrim(config('repositories.repository_interfaces_namespace'), '\\').'\\'; |
|
| 55 | + $skipRepositories = config('repositories.skip'); |
|
| 56 | + $implementationBindings = config('repositories.bindings'); |
|
| 57 | + $defaultImplementation = $this->findDefaultImplementation($implementationBindings); |
|
| 58 | 58 | |
| 59 | - if ( \File::exists( $repositoriesBasePath ) ) |
|
| 59 | + if (\File::exists($repositoriesBasePath)) |
|
| 60 | 60 | { |
| 61 | - $allRepos = \File::files( $repositoriesBasePath ); |
|
| 61 | + $allRepos = \File::files($repositoriesBasePath); |
|
| 62 | 62 | |
| 63 | - foreach( $allRepos as $repo ) |
|
| 63 | + foreach ($allRepos as $repo) |
|
| 64 | 64 | { |
| 65 | 65 | $implementation = $defaultImplementation; |
| 66 | - $interfaceName = pathinfo( $repo, PATHINFO_FILENAME ); |
|
| 67 | - if ( in_array( $interfaceName, $skipRepositories ) ) continue; |
|
| 66 | + $interfaceName = pathinfo($repo, PATHINFO_FILENAME); |
|
| 67 | + if (in_array($interfaceName, $skipRepositories)) continue; |
|
| 68 | 68 | else |
| 69 | 69 | { |
| 70 | - $commonName = str_replace( 'Interface', '', $interfaceName ); |
|
| 70 | + $commonName = str_replace('Interface', '', $interfaceName); |
|
| 71 | 71 | $interfaceFullClassName = $baseNamespace.$interfaceName; |
| 72 | 72 | |
| 73 | - foreach( $implementationBindings as $engine => $bindRepositories ) |
|
| 73 | + foreach ($implementationBindings as $engine => $bindRepositories) |
|
| 74 | 74 | { |
| 75 | - if ( $bindRepositories === 'default' ) continue; |
|
| 76 | - else if ( in_array( $interfaceName, $bindRepositories ) ) |
|
| 75 | + if ($bindRepositories === 'default') continue; |
|
| 76 | + else if (in_array($interfaceName, $bindRepositories)) |
|
| 77 | 77 | { |
| 78 | 78 | $implementation = $engine; |
| 79 | 79 | break; |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $fullClassName = $baseNamespace.ucfirst( Str::camel( $implementation ) ).'\\'.$commonName; |
|
| 83 | + $fullClassName = $baseNamespace.ucfirst(Str::camel($implementation)).'\\'.$commonName; |
|
| 84 | 84 | |
| 85 | - if ( class_exists( $fullClassName ) ) |
|
| 85 | + if (class_exists($fullClassName)) |
|
| 86 | 86 | { |
| 87 | 87 | // Bind the class. |
| 88 | - $this->app->bind( $interfaceFullClassName, function ( $app ) use ( $fullClassName ) |
|
| 88 | + $this->app->bind($interfaceFullClassName, function($app) use ($fullClassName) |
|
| 89 | 89 | { |
| 90 | - return $app->make( $fullClassName ); |
|
| 90 | + return $app->make($fullClassName); |
|
| 91 | 91 | }); |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | * @param $implementations |
| 101 | 101 | * @return array|mixed|string |
| 102 | 102 | */ |
| 103 | - private function findDefaultImplementation( $implementations ) |
|
| 103 | + private function findDefaultImplementation($implementations) |
|
| 104 | 104 | { |
| 105 | - $filtered = array_filter( $implementations, function( $k ) { |
|
| 105 | + $filtered = array_filter($implementations, function($k) { |
|
| 106 | 106 | return $k === 'default'; |
| 107 | 107 | }); |
| 108 | 108 | |
| 109 | 109 | $default = array_keys($filtered); |
| 110 | - $default = is_array( $default ) ? $default[0] : $default; |
|
| 110 | + $default = is_array($default) ? $default[0] : $default; |
|
| 111 | 111 | |
| 112 | 112 | return $default ? $default : 'eloquent'; |
| 113 | 113 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | private function registerRepositoryGenerator() |
| 119 | 119 | { |
| 120 | - $this->app->singleton('command.repository', function ($app) |
|
| 120 | + $this->app->singleton('command.repository', function($app) |
|
| 121 | 121 | { |
| 122 | 122 | return $app['OkayBueno\Repositories\Commands\MakeRepositoryCommand']; |
| 123 | 123 | }); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | private function registerCriteriaGenerator() |
| 133 | 133 | { |
| 134 | - $this->app->singleton('command.criteria', function ($app) |
|
| 134 | + $this->app->singleton('command.criteria', function($app) |
|
| 135 | 135 | { |
| 136 | 136 | return $app['OkayBueno\Repositories\Commands\MakeCriteriaCommand']; |
| 137 | 137 | }); |
@@ -48,7 +48,9 @@ discard block |
||
| 48 | 48 | $this->eagerLoadRelations(); |
| 49 | 49 | $this->applyCriteria(); |
| 50 | 50 | |
| 51 | - if ( !is_null( $value ) ) $this->model = $this->model->where( $field, $value ); |
|
| 51 | + if ( !is_null( $value ) ) { |
|
| 52 | + $this->model = $this->model->where( $field, $value ); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $result = $this->model->first( $columns ); |
| 54 | 56 | |
@@ -68,7 +70,9 @@ discard block |
||
| 68 | 70 | $this->eagerLoadRelations(); |
| 69 | 71 | $this->applyCriteria(); |
| 70 | 72 | |
| 71 | - if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value ); |
|
| 73 | + if ( !is_null( $value ) && !is_null( $field ) ) { |
|
| 74 | + $this->model = $this->model->where( $field, $value ); |
|
| 75 | + } |
|
| 72 | 76 | |
| 73 | 77 | $result = $this->model->get( $columns ); |
| 74 | 78 | |
@@ -115,7 +119,9 @@ discard block |
||
| 115 | 119 | */ |
| 116 | 120 | public function with( $relations ) |
| 117 | 121 | { |
| 118 | - if ( is_string( $relations ) ) $relations = func_get_args(); |
|
| 122 | + if ( is_string( $relations ) ) { |
|
| 123 | + $relations = func_get_args(); |
|
| 124 | + } |
|
| 119 | 125 | |
| 120 | 126 | $this->with = $relations; |
| 121 | 127 | |
@@ -208,7 +214,9 @@ discard block |
||
| 208 | 214 | // Single update. |
| 209 | 215 | $this->model->where( $field, $value)->update( $cleanFields ); |
| 210 | 216 | |
| 211 | - foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V; |
|
| 217 | + foreach( $cleanFields as $F => $V ) { |
|
| 218 | + $this->model->{$F} = $V; |
|
| 219 | + } |
|
| 212 | 220 | |
| 213 | 221 | $returnedVal = $this->model; |
| 214 | 222 | } else |
@@ -234,11 +242,15 @@ discard block |
||
| 234 | 242 | { |
| 235 | 243 | $this->applyCriteria(); |
| 236 | 244 | |
| 237 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete(); |
|
| 238 | - else |
|
| 245 | + if ( !is_null( $value ) ) { |
|
| 246 | + $result = $this->model->where( $field, $value )->delete(); |
|
| 247 | + } else |
|
| 239 | 248 | { |
| 240 | - if ( !empty( $this->criteria ) ) $result = $this->model->delete(); |
|
| 241 | - else $result = FALSE; |
|
| 249 | + if ( !empty( $this->criteria ) ) { |
|
| 250 | + $result = $this->model->delete(); |
|
| 251 | + } else { |
|
| 252 | + $result = FALSE; |
|
| 253 | + } |
|
| 242 | 254 | } |
| 243 | 255 | |
| 244 | 256 | $this->resetScope(); |
@@ -279,11 +291,15 @@ discard block |
||
| 279 | 291 | { |
| 280 | 292 | $this->applyCriteria(); |
| 281 | 293 | |
| 282 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 283 | - else |
|
| 294 | + if ( !is_null( $value ) ) { |
|
| 295 | + $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 296 | + } else |
|
| 284 | 297 | { |
| 285 | - if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete(); |
|
| 286 | - else $result = FALSE; |
|
| 298 | + if ( !empty( $this->criteria ) ) { |
|
| 299 | + $result = $this->model->forceDelete(); |
|
| 300 | + } else { |
|
| 301 | + $result = FALSE; |
|
| 302 | + } |
|
| 287 | 303 | } |
| 288 | 304 | |
| 289 | 305 | $this->resetScope(); |
@@ -329,7 +345,9 @@ discard block |
||
| 329 | 345 | { |
| 330 | 346 | foreach( $this->criteria as $criteria ) |
| 331 | 347 | { |
| 332 | - if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this ); |
|
| 348 | + if( $criteria instanceof CriteriaInterface ) { |
|
| 349 | + $this->model = $criteria->apply( $this->model, $this ); |
|
| 350 | + } |
|
| 333 | 351 | } |
| 334 | 352 | } |
| 335 | 353 | |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | * @param Model $model |
| 26 | 26 | * @throws \ReflectionException |
| 27 | 27 | */ |
| 28 | - public function __construct( Model $model ) |
|
| 28 | + public function __construct(Model $model) |
|
| 29 | 29 | { |
| 30 | 30 | $this->model = $model; |
| 31 | 31 | |
| 32 | 32 | // A clean copy of the model is needed when the scope needs to be reset. |
| 33 | - $reflex = new \ReflectionClass( $model ); |
|
| 33 | + $reflex = new \ReflectionClass($model); |
|
| 34 | 34 | $this->modelClassName = $reflex->getName(); |
| 35 | 35 | |
| 36 | 36 | $this->skipCriteria = FALSE; |
@@ -48,9 +48,9 @@ discard block |
||
| 48 | 48 | $this->eagerLoadRelations(); |
| 49 | 49 | $this->applyCriteria(); |
| 50 | 50 | |
| 51 | - if ( !is_null( $value ) ) $this->model = $this->model->where( $field, $value ); |
|
| 51 | + if (!is_null($value)) $this->model = $this->model->where($field, $value); |
|
| 52 | 52 | |
| 53 | - $result = $this->model->first( $columns ); |
|
| 53 | + $result = $this->model->first($columns); |
|
| 54 | 54 | |
| 55 | 55 | $this->resetScope(); |
| 56 | 56 | |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | $this->eagerLoadRelations(); |
| 69 | 69 | $this->applyCriteria(); |
| 70 | 70 | |
| 71 | - if ( !is_null( $value ) && !is_null( $field ) ) $this->model = $this->model->where( $field, $value ); |
|
| 71 | + if (!is_null($value) && !is_null($field)) $this->model = $this->model->where($field, $value); |
|
| 72 | 72 | |
| 73 | - $result = $this->model->get( $columns ); |
|
| 73 | + $result = $this->model->get($columns); |
|
| 74 | 74 | |
| 75 | 75 | $this->resetScope(); |
| 76 | 76 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | $this->eagerLoadRelations(); |
| 89 | 89 | $this->applyCriteria(); |
| 90 | - $result = $this->model->whereIn( $field, $value )->get( $columns ); |
|
| 90 | + $result = $this->model->whereIn($field, $value)->get($columns); |
|
| 91 | 91 | |
| 92 | 92 | $this->resetScope(); |
| 93 | 93 | |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | * @param array $columns |
| 99 | 99 | * @return \Illuminate\Database\Eloquent\Collection|static[] |
| 100 | 100 | */ |
| 101 | - public function findAll( array $columns = ['*'] ) |
|
| 101 | + public function findAll(array $columns = ['*']) |
|
| 102 | 102 | { |
| 103 | 103 | $this->eagerLoadRelations(); |
| 104 | 104 | $this->applyCriteria(); |
| 105 | - $result = $this->model->all( $columns ); |
|
| 105 | + $result = $this->model->all($columns); |
|
| 106 | 106 | |
| 107 | 107 | $this->resetScope(); |
| 108 | 108 | |
@@ -113,9 +113,9 @@ discard block |
||
| 113 | 113 | * @param array|string $relations |
| 114 | 114 | * @return $this |
| 115 | 115 | */ |
| 116 | - public function with( $relations ) |
|
| 116 | + public function with($relations) |
|
| 117 | 117 | { |
| 118 | - if ( is_string( $relations ) ) $relations = func_get_args(); |
|
| 118 | + if (is_string($relations)) $relations = func_get_args(); |
|
| 119 | 119 | |
| 120 | 120 | $this->with = $relations; |
| 121 | 121 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param CriteriaInterface $criteria |
| 128 | 128 | * @return $this |
| 129 | 129 | */ |
| 130 | - public function addCriteria( CriteriaInterface $criteria) |
|
| 130 | + public function addCriteria(CriteriaInterface $criteria) |
|
| 131 | 131 | { |
| 132 | 132 | $this->criteria[] = $criteria; |
| 133 | 133 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param bool $status |
| 140 | 140 | * @return $this |
| 141 | 141 | */ |
| 142 | - public function skipCriteria( $status = TRUE ) |
|
| 142 | + public function skipCriteria($status = TRUE) |
|
| 143 | 143 | { |
| 144 | 144 | $this->skipCriteria = $status; |
| 145 | 145 | return $this; |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | { |
| 156 | 156 | $this->eagerLoadRelations(); |
| 157 | 157 | $this->applyCriteria(); |
| 158 | - $result = $this->model->paginate( $perPage, $columns ); |
|
| 158 | + $result = $this->model->paginate($perPage, $columns); |
|
| 159 | 159 | |
| 160 | 160 | $this->resetScope(); |
| 161 | 161 | |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | * @param int $currentPage |
| 168 | 168 | * @return $this |
| 169 | 169 | */ |
| 170 | - public function setCurrentPage( $currentPage ) |
|
| 170 | + public function setCurrentPage($currentPage) |
|
| 171 | 171 | { |
| 172 | - \Illuminate\Pagination\Paginator::currentPageResolver(function() use ( $currentPage ) |
|
| 172 | + \Illuminate\Pagination\Paginator::currentPageResolver(function() use ($currentPage) |
|
| 173 | 173 | { |
| 174 | 174 | return $currentPage; |
| 175 | 175 | }); |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function create(array $data) |
| 186 | 186 | { |
| 187 | - $cleanFields = $this->cleanUnfillableFields( $data ); |
|
| 187 | + $cleanFields = $this->cleanUnfillableFields($data); |
|
| 188 | 188 | |
| 189 | - $createdObject = $this->model->create( $cleanFields ); |
|
| 189 | + $createdObject = $this->model->create($cleanFields); |
|
| 190 | 190 | |
| 191 | 191 | $this->resetScope(); |
| 192 | 192 | |
@@ -201,14 +201,14 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | public function updateBy(array $data, $value = NULL, $field = 'id') |
| 203 | 203 | { |
| 204 | - $cleanFields = $this->cleanUnfillableFields( $data ); |
|
| 204 | + $cleanFields = $this->cleanUnfillableFields($data); |
|
| 205 | 205 | |
| 206 | - if ( !is_null( $value ) ) |
|
| 206 | + if (!is_null($value)) |
|
| 207 | 207 | { |
| 208 | 208 | // Single update. |
| 209 | - $this->model->where( $field, $value)->update( $cleanFields ); |
|
| 209 | + $this->model->where($field, $value)->update($cleanFields); |
|
| 210 | 210 | |
| 211 | - foreach( $cleanFields as $F => $V ) $this->model->{$F} = $V; |
|
| 211 | + foreach ($cleanFields as $F => $V) $this->model->{$F} = $V; |
|
| 212 | 212 | |
| 213 | 213 | $returnedVal = $this->model; |
| 214 | 214 | } else |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | // Mass update. |
| 217 | 217 | $this->applyCriteria(); |
| 218 | 218 | |
| 219 | - $returnedVal = $this->model->update( $cleanFields ); |
|
| 219 | + $returnedVal = $this->model->update($cleanFields); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | $this->resetScope(); |
@@ -230,14 +230,14 @@ discard block |
||
| 230 | 230 | * @return bool |
| 231 | 231 | * @throws \Exception |
| 232 | 232 | */ |
| 233 | - public function delete( $value = null, $field = 'id' ) |
|
| 233 | + public function delete($value = null, $field = 'id') |
|
| 234 | 234 | { |
| 235 | 235 | $this->applyCriteria(); |
| 236 | 236 | |
| 237 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->delete(); |
|
| 237 | + if (!is_null($value)) $result = $this->model->where($field, $value)->delete(); |
|
| 238 | 238 | else |
| 239 | 239 | { |
| 240 | - if ( !empty( $this->criteria ) ) $result = $this->model->delete(); |
|
| 240 | + if (!empty($this->criteria)) $result = $this->model->delete(); |
|
| 241 | 241 | else $result = FALSE; |
| 242 | 242 | } |
| 243 | 243 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | public function resetScope() |
| 266 | 266 | { |
| 267 | 267 | $this->criteria = []; |
| 268 | - $this->skipCriteria( FALSE ); |
|
| 268 | + $this->skipCriteria(FALSE); |
|
| 269 | 269 | $this->model = new $this->modelClassName(); |
| 270 | 270 | return $this; |
| 271 | 271 | } |
@@ -279,10 +279,10 @@ discard block |
||
| 279 | 279 | { |
| 280 | 280 | $this->applyCriteria(); |
| 281 | 281 | |
| 282 | - if ( !is_null( $value ) ) $result = $this->model->where( $field, $value )->forceDelete(); |
|
| 282 | + if (!is_null($value)) $result = $this->model->where($field, $value)->forceDelete(); |
|
| 283 | 283 | else |
| 284 | 284 | { |
| 285 | - if ( !empty( $this->criteria ) ) $result = $this->model->forceDelete(); |
|
| 285 | + if (!empty($this->criteria)) $result = $this->model->forceDelete(); |
|
| 286 | 286 | else $result = FALSE; |
| 287 | 287 | } |
| 288 | 288 | |
@@ -300,10 +300,10 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | protected function eagerLoadRelations() |
| 302 | 302 | { |
| 303 | - if ( is_array( $this->with ) ) |
|
| 303 | + if (is_array($this->with)) |
|
| 304 | 304 | { |
| 305 | - $with = new With( $this->with ); |
|
| 306 | - $this->addCriteria( $with ); |
|
| 305 | + $with = new With($this->with); |
|
| 306 | + $this->addCriteria($with); |
|
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
@@ -312,9 +312,9 @@ discard block |
||
| 312 | 312 | * @param array $data |
| 313 | 313 | * @return array |
| 314 | 314 | */ |
| 315 | - protected function cleanUnfillableFields( array $data ) |
|
| 315 | + protected function cleanUnfillableFields(array $data) |
|
| 316 | 316 | { |
| 317 | - return array_filter($data, function ($key) { |
|
| 317 | + return array_filter($data, function($key) { |
|
| 318 | 318 | return $this->model->isFillable($key); |
| 319 | 319 | }, ARRAY_FILTER_USE_KEY); |
| 320 | 320 | } |
@@ -324,11 +324,11 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | protected function applyCriteria() |
| 326 | 326 | { |
| 327 | - if( !$this->skipCriteria ) |
|
| 327 | + if (!$this->skipCriteria) |
|
| 328 | 328 | { |
| 329 | - foreach( $this->criteria as $criteria ) |
|
| 329 | + foreach ($this->criteria as $criteria) |
|
| 330 | 330 | { |
| 331 | - if( $criteria instanceof CriteriaInterface ) $this->model = $criteria->apply( $this->model, $this ); |
|
| 331 | + if ($criteria instanceof CriteriaInterface) $this->model = $criteria->apply($this->model, $this); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
@@ -23,9 +23,9 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | - * @param mixed $queryBuilder |
|
| 27 | - * @return mixed |
|
| 28 | - */ |
|
| 26 | + * @param mixed $queryBuilder |
|
| 27 | + * @return mixed |
|
| 28 | + */ |
|
| 29 | 29 | public function apply( $queryBuilder ) |
| 30 | 30 | { |
| 31 | 31 | // Do something with the query builder and return it. |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * With constructor. |
| 18 | 18 | * @param array $with |
| 19 | 19 | */ |
| 20 | - public function __construct( array $with = [] ) |
|
| 20 | + public function __construct(array $with = []) |
|
| 21 | 21 | { |
| 22 | 22 | $this->with = $with; |
| 23 | 23 | } |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | * @param mixed $queryBuilder |
| 27 | 27 | * @return mixed |
| 28 | 28 | */ |
| 29 | - public function apply( $queryBuilder ) |
|
| 29 | + public function apply($queryBuilder) |
|
| 30 | 30 | { |
| 31 | 31 | // Do something with the query builder and return it. |
| 32 | - if ( $this->with ) $queryBuilder->with( $this->with ); |
|
| 32 | + if ($this->with) $queryBuilder->with($this->with); |
|
| 33 | 33 | |
| 34 | 34 | return $queryBuilder; |
| 35 | 35 | } |
@@ -29,7 +29,9 @@ |
||
| 29 | 29 | public function apply( $queryBuilder ) |
| 30 | 30 | { |
| 31 | 31 | // Do something with the query builder and return it. |
| 32 | - if ( $this->with ) $queryBuilder->with( $this->with ); |
|
| 32 | + if ( $this->with ) { |
|
| 33 | + $queryBuilder->with( $this->with ); |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | return $queryBuilder; |
| 35 | 37 | } |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | * @param mixed $queryBuilder |
| 15 | 15 | * @return mixed |
| 16 | 16 | */ |
| 17 | - public function apply( $queryBuilder ) |
|
| 17 | + public function apply($queryBuilder) |
|
| 18 | 18 | { |
| 19 | 19 | return $queryBuilder->inRandomOrder(); |
| 20 | 20 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param $field |
| 19 | 19 | * @param array $list |
| 20 | 20 | */ |
| 21 | - public function __construct( $field, array $list ) |
|
| 21 | + public function __construct($field, array $list) |
|
| 22 | 22 | { |
| 23 | 23 | $this->field = $field; |
| 24 | 24 | $this->list = $list; |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * @param mixed $queryBuilder |
| 29 | 29 | * @return mixed |
| 30 | 30 | */ |
| 31 | - public function apply( $queryBuilder ) |
|
| 31 | + public function apply($queryBuilder) |
|
| 32 | 32 | { |
| 33 | 33 | // Do something with the query builder and return it. |
| 34 | - return $queryBuilder->whereNotIn( $this->field, $this->list ); |
|
| 34 | + return $queryBuilder->whereNotIn($this->field, $this->list); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @param array $list |
| 21 | 21 | * @param string $field |
| 22 | 22 | */ |
| 23 | - public function __construct( $relationName, array $list, $field = 'id' ) |
|
| 23 | + public function __construct($relationName, array $list, $field = 'id') |
|
| 24 | 24 | { |
| 25 | 25 | $this->relationName = $relationName; |
| 26 | 26 | $this->list = $list; |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | * @param mixed $queryBuilder |
| 32 | 32 | * @return mixed |
| 33 | 33 | */ |
| 34 | - public function apply( $queryBuilder ) |
|
| 34 | + public function apply($queryBuilder) |
|
| 35 | 35 | { |
| 36 | 36 | // Do something with the query builder and return it. |
| 37 | - return $queryBuilder->whereHas( $this->relationName, function ($query) { |
|
| 38 | - $query->whereIn( $this->field, $this->list); |
|
| 37 | + return $queryBuilder->whereHas($this->relationName, function($query) { |
|
| 38 | + $query->whereIn($this->field, $this->list); |
|
| 39 | 39 | }); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @param $field |
| 19 | 19 | * @param array $list |
| 20 | 20 | */ |
| 21 | - public function __construct( $field, array $list ) |
|
| 21 | + public function __construct($field, array $list) |
|
| 22 | 22 | { |
| 23 | 23 | $this->field = $field; |
| 24 | 24 | $this->list = $list; |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | * @param mixed $queryBuilder |
| 29 | 29 | * @return mixed |
| 30 | 30 | */ |
| 31 | - public function apply( $queryBuilder ) |
|
| 31 | + public function apply($queryBuilder) |
|
| 32 | 32 | { |
| 33 | 33 | // Do something with the query builder and return it. |
| 34 | - return $queryBuilder->whereIn( $this->field, $this->list ); |
|
| 34 | + return $queryBuilder->whereIn($this->field, $this->list); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |