Conditions | 11 |
Paths | 256 |
Total Lines | 35 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
50 | public function create($service, array $args = array()) |
||
51 | { |
||
52 | // merge args with default |
||
53 | $args = array_merge($this->args, $args); |
||
54 | $namespace = isset($args['namespace']) ? $args['namespace'] : ''; |
||
55 | $defaultLifetime = isset($args['defaultLifetime']) ? $args['defaultLifetime'] : 0; |
||
56 | $directory = isset($args['directory']) ? $args['directory'] : null; |
||
57 | $version = isset($args['version']) ? $args['version'] : null; |
||
58 | |||
59 | // In-memory caches are typically more resource constrained (number of items and storage space). |
||
60 | // Give cache consumers an opt-out if they are expecting to create large caches with long lifetimes. |
||
61 | $useInMemoryCache = isset($args['useInMemoryCache']) ? $args['useInMemoryCache'] : true; |
||
62 | |||
63 | // Check support |
||
64 | $apcuSupported = ($this->isAPCUSupported() && $useInMemoryCache); |
||
65 | $phpFilesSupported = $this->isPHPFilesSupported(); |
||
66 | |||
67 | // If apcu isn't supported, phpfiles is the next best preference |
||
68 | if (!$apcuSupported && $phpFilesSupported) { |
||
69 | return $this->createCache(PhpFilesCache::class, [$namespace, $defaultLifetime, $directory]); |
||
70 | } |
||
71 | |||
72 | // Create filessytem cache |
||
73 | $fs = $this->createCache(FilesystemCache::class, [$namespace, $defaultLifetime, $directory]); |
||
74 | if (!$apcuSupported) { |
||
75 | return $fs; |
||
76 | } |
||
77 | |||
78 | // Chain this cache with ApcuCache |
||
79 | // Note that the cache lifetime will be shorter there by default, to ensure there's enough |
||
80 | // resources for "hot cache" items in APCu as a resource constrained in memory cache. |
||
81 | $apcuNamespace = $namespace . ($namespace ? '_' : '') . md5(BASE_PATH); |
||
82 | $apcu = $this->createCache(ApcuCache::class, [$apcuNamespace, (int) $defaultLifetime / 5, $version]); |
||
83 | |||
84 | return $this->createCache(ChainCache::class, [[$apcu, $fs]]); |
||
85 | } |
||
136 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..