| Total Complexity | 8 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 90% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | final class LockManager implements LockManagerInterface |
||
| 10 | { |
||
| 11 | private StuConfigInterface $config; |
||
| 12 | |||
| 13 | 2 | public function __construct(StuConfigInterface $config) |
|
| 14 | { |
||
| 15 | 2 | $this->config = $config; |
|
| 16 | } |
||
| 17 | |||
| 18 | 1 | public function setLock(int $batchGroupId, LockTypeEnum $type): void |
|
| 19 | { |
||
| 20 | 1 | @touch($this->getLockPath($batchGroupId, $type)); |
|
|
|
|||
| 21 | } |
||
| 22 | |||
| 23 | 1 | public function clearLock(int $batchGroupId, LockTypeEnum $type): void |
|
| 24 | { |
||
| 25 | 1 | @unlink($this->getLockPath($batchGroupId, $type)); |
|
| 26 | } |
||
| 27 | |||
| 28 | 1 | public function isLocked(int $entityId, LockTypeEnum $type): bool |
|
| 29 | { |
||
| 30 | 1 | return @file_exists($this->getLockPath($entityId % $this->getGroupCount($type) + 1, $type)); |
|
| 31 | } |
||
| 32 | |||
| 33 | 1 | private function getLockPath(int $batchGroupId, LockTypeEnum $type): string |
|
| 40 | 1 | ); |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | private function getGroupCount(LockTypeEnum $type): int |
|
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 |
If you suppress an error, we recommend checking for the error condition explicitly: