Skip to content

Commit 88cb956

Browse files
committed
throw RuntimeException-s
1 parent 84696d2 commit 88cb956

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require-dev": {
16-
"phpspec/phpspec": "~2.0",
16+
"phpspec/phpspec": "^2.4",
1717
"php-vfs/php-vfs": "~1.2"
1818
},
1919
"require": {

src/FileLock.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Psr\Log\LoggerInterface;
66
use Psr\Log\NullLogger;
7+
use TH\Lock\RuntimeException;
78

89
class FileLock implements Lock
910
{
@@ -81,7 +82,7 @@ private function tryAcquire($operation, $lock_type)
8182
if (!$this->flock($operation)) {
8283
$this->logger->debug("could not acquire {lock_type} lock on {lock_file}", $log_data);
8384

84-
throw new \RuntimeException(
85+
throw new RuntimeException(
8586
"Could not acquire $lock_type lock on {$this->lock_file}"
8687
);
8788

@@ -122,7 +123,7 @@ private function flock($operation)
122123
}
123124

124125
if (!is_resource($this->fh)) {
125-
throw new \RuntimeException("Could not open lock file {$this->lock_file}");
126+
throw new RuntimeException("Could not open lock file {$this->lock_file}");
126127
}
127128

128129
return flock($this->fh, $operation);

src/Lock.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ interface Lock
88
{
99
/**
1010
* Acquire a lock on the resource
11+
* @throws \RuntimeException thrown if the lock could not be acquired
1112
* @return void
1213
*/
1314
public function acquire();
1415

1516
/**
16-
* Release lock on the resource
17+
* Release lock on the resource. If the lock has not been acquired, does nothing.
18+
* @throws \RuntimeException thrown if the lock could not be released
1719
* @return void
1820
*/
1921
public function release();

src/RuntimeException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace TH\Lock;
4+
5+
class RuntimeException extends \RuntimeException
6+
{
7+
}

0 commit comments

Comments
 (0)