| Conditions | 10 |
| Paths | 42 |
| Total Lines | 94 |
| Code Lines | 37 |
| 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 |
||
| 76 | protected function getLocksOnServer( $lockSrv, array $pathsByType ) { |
||
| 77 | $status = StatusValue::newGood(); |
||
| 78 | |||
| 79 | $pathList = call_user_func_array( 'array_merge', array_values( $pathsByType ) ); |
||
| 80 | |||
| 81 | $server = $this->lockServers[$lockSrv]; |
||
| 82 | $conn = $this->redisPool->getConnection( $server, $this->logger ); |
||
| 83 | if ( !$conn ) { |
||
| 84 | foreach ( $pathList as $path ) { |
||
| 85 | $status->fatal( 'lockmanager-fail-acquirelock', $path ); |
||
| 86 | } |
||
| 87 | |||
| 88 | return $status; |
||
| 89 | } |
||
| 90 | |||
| 91 | $pathsByKey = []; // (type:hash => path) map |
||
| 92 | foreach ( $pathsByType as $type => $paths ) { |
||
| 93 | $typeString = ( $type == LockManager::LOCK_SH ) ? 'SH' : 'EX'; |
||
| 94 | foreach ( $paths as $path ) { |
||
| 95 | $pathsByKey[$this->recordKeyForPath( $path, $typeString )] = $path; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | try { |
||
| 100 | static $script = |
||
| 101 | /** @lang Lua */ |
||
| 102 | <<<LUA |
||
| 103 | local failed = {} |
||
| 104 | -- Load input params (e.g. session, ttl, time of request) |
||
| 105 | local rSession, rTTL, rMaxTTL, rTime = unpack(ARGV) |
||
| 106 | -- Check that all the locks can be acquired |
||
| 107 | for i,requestKey in ipairs(KEYS) do |
||
| 108 | local _, _, rType, resourceKey = string.find(requestKey,"(%w+):(%w+)$") |
||
| 109 | local keyIsFree = true |
||
| 110 | local currentLocks = redis.call('hKeys',resourceKey) |
||
| 111 | for i,lockKey in ipairs(currentLocks) do |
||
| 112 | -- Get the type and session of this lock |
||
| 113 | local _, _, type, session = string.find(lockKey,"(%w+):(%w+)") |
||
| 114 | -- Check any locks that are not owned by this session |
||
| 115 | if session ~= rSession then |
||
| 116 | local lockExpiry = redis.call('hGet',resourceKey,lockKey) |
||
| 117 | if 1*lockExpiry < 1*rTime then |
||
| 118 | -- Lock is stale, so just prune it out |
||
| 119 | redis.call('hDel',resourceKey,lockKey) |
||
| 120 | elseif rType == 'EX' or type == 'EX' then |
||
| 121 | keyIsFree = false |
||
| 122 | break |
||
| 123 | end |
||
| 124 | end |
||
| 125 | end |
||
| 126 | if not keyIsFree then |
||
| 127 | failed[#failed+1] = requestKey |
||
| 128 | end |
||
| 129 | end |
||
| 130 | -- If all locks could be acquired, then do so |
||
| 131 | if #failed == 0 then |
||
| 132 | for i,requestKey in ipairs(KEYS) do |
||
| 133 | local _, _, rType, resourceKey = string.find(requestKey,"(%w+):(%w+)$") |
||
| 134 | redis.call('hSet',resourceKey,rType .. ':' .. rSession,rTime + rTTL) |
||
| 135 | -- In addition to invalidation logic, be sure to garbage collect |
||
| 136 | redis.call('expire',resourceKey,rMaxTTL) |
||
| 137 | end |
||
| 138 | end |
||
| 139 | return failed |
||
| 140 | LUA; |
||
| 141 | $res = $conn->luaEval( $script, |
||
| 142 | array_merge( |
||
| 143 | array_keys( $pathsByKey ), // KEYS[0], KEYS[1],...,KEYS[N] |
||
| 144 | [ |
||
| 145 | $this->session, // ARGV[1] |
||
| 146 | $this->lockTTL, // ARGV[2] |
||
| 147 | self::MAX_LOCK_TTL, // ARGV[3] |
||
| 148 | time() // ARGV[4] |
||
| 149 | ] |
||
| 150 | ), |
||
| 151 | count( $pathsByKey ) # number of first argument(s) that are keys |
||
| 152 | ); |
||
| 153 | } catch ( RedisException $e ) { |
||
|
|
|||
| 154 | $res = false; |
||
| 155 | $this->redisPool->handleError( $conn, $e ); |
||
| 156 | } |
||
| 157 | |||
| 158 | if ( $res === false ) { |
||
| 159 | foreach ( $pathList as $path ) { |
||
| 160 | $status->fatal( 'lockmanager-fail-acquirelock', $path ); |
||
| 161 | } |
||
| 162 | } else { |
||
| 163 | foreach ( $res as $key ) { |
||
| 164 | $status->fatal( 'lockmanager-fail-acquirelock', $pathsByKey[$key] ); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | return $status; |
||
| 169 | } |
||
| 170 | |||
| 277 |
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.