Skip to content

Commit 1f77833

Browse files
committed
PSR-12
1 parent b5e5c97 commit 1f77833

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

Diff for: spec/TH/Lock/FileFactorySpec.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace spec\TH\Lock;
44

5-
use VirtualFileSystem\FileSystem;
65
use PhpSpec\ObjectBehavior;
76
use Prophecy\Argument;
7+
use TH\Lock\Factory;
8+
use TH\Lock\FileFactory;
9+
use TH\Lock\FileLock;
10+
use VirtualFileSystem\FileSystem;
811

912
class FileFactorySpec extends ObjectBehavior
1013
{
@@ -21,12 +24,12 @@ public function let()
2124

2225
public function it_is_initializable()
2326
{
24-
$this->shouldHaveType('TH\Lock\FileFactory');
25-
$this->shouldImplement('TH\Lock\Factory');
27+
$this->shouldHaveType(FileFactory::class);
28+
$this->shouldImplement(Factory::class);
2629
}
2730

2831
public function it_should_create_a_file_lock()
2932
{
30-
$this->create('some resource identifier')->shouldhaveType('TH\Lock\FileLock');
33+
$this->create('some resource identifier')->shouldhaveType(FileLock::class);
3134
}
3235
}

Diff for: spec/TH/Lock/FileLockSpec.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace spec\TH\Lock;
44

5-
use VirtualFileSystem\FileSystem;
6-
use TH\Lock\FileLock;
75
use PhpSpec\ObjectBehavior;
86
use Prophecy\Argument;
9-
use Exception;
7+
use TH\Lock\FileLock;
8+
use TH\Lock\Lock;
9+
use VirtualFileSystem\FileSystem;
1010

1111
class FileLockSpec extends ObjectBehavior
1212
{
@@ -25,20 +25,20 @@ public function let()
2525

2626
public function it_is_initializable()
2727
{
28-
$this->shouldHaveType('TH\Lock\FileLock');
29-
$this->shouldImplement('TH\Lock\Lock');
28+
$this->shouldHaveType(FileLock::class);
29+
$this->shouldImplement(Lock::class);
3030
}
3131

3232
public function it_should_acquire_an_exclusive_lock()
3333
{
3434
$this->acquire();
3535

3636
if (!file_exists($this->lock_file)) {
37-
throw new Exception('Lock file was not created');
37+
throw new \Exception('Lock file was not created');
3838
}
3939

4040
if (flock(fopen($this->lock_file, 'r'), LOCK_SH|LOCK_NB)) {
41-
throw new Exception('Lock file was not exclusively locked');
41+
throw new \Exception('Lock file was not exclusively locked');
4242
}
4343
}
4444

@@ -49,15 +49,15 @@ public function it_should_acquire_a_shared_lock()
4949
$this->acquire();
5050

5151
if (!file_exists($this->lock_file)) {
52-
throw new Exception('Lock file was not created');
52+
throw new \Exception('Lock file was not created');
5353
}
5454

5555
if (flock(fopen($this->lock_file, 'r'), LOCK_EX|LOCK_NB)) {
56-
throw new Exception('Lock file was not locked againt exclusive lock');
56+
throw new \Exception('Lock file was not locked againt exclusive lock');
5757
}
5858

5959
if (!flock(fopen($this->lock_file, 'r'), LOCK_SH|LOCK_NB)) {
60-
throw new Exception('Lock file was not shared locked');
60+
throw new \Exception('Lock file was not shared locked');
6161
}
6262
}
6363

@@ -67,7 +67,7 @@ public function it_should_release_a_lock()
6767
$this->release();
6868

6969
if (!flock(fopen($this->lock_file, 'r'), LOCK_EX|LOCK_NB)) {
70-
throw new Exception('Lock file was not released');
70+
throw new \Exception('Lock file was not released');
7171
}
7272
}
7373

@@ -87,7 +87,7 @@ public function it_remove_its_lock_file_if_not_locked()
8787
$this->release();
8888

8989
if (file_exists($this->lock_file)) {
90-
throw new Exception('Lock file was not removed');
90+
throw new \Exception('Lock file was not removed');
9191
}
9292
}
9393

@@ -102,7 +102,7 @@ public function it_does_not_remove_its_lock_file_if_still_locked()
102102
$this->release();
103103

104104
if (!file_exists($this->lock_file)) {
105-
throw new Exception('Lock file was removed');
105+
throw new \Exception('Lock file was removed');
106106
}
107107
}
108108

@@ -115,11 +115,11 @@ public function it_can_acquire_then_release_and_acquire_again()
115115
$this->acquire();
116116

117117
if (!file_exists($this->lock_file)) {
118-
throw new Exception('Lock file was not created');
118+
throw new \Exception('Lock file was not created');
119119
}
120120

121121
if (flock(fopen($this->lock_file, 'r'), LOCK_SH|LOCK_NB)) {
122-
throw new Exception('Lock file was not exclusively locked');
122+
throw new \Exception('Lock file was not exclusively locked');
123123
}
124124

125125
$this->release();

Diff for: src/FileLock.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Psr\Log\LoggerInterface;
66
use Psr\Log\NullLogger;
7-
use Exception;
87

98
class FileLock implements Lock
109
{
@@ -82,7 +81,7 @@ private function tryAcquire($operation, $lock_type)
8281
if (!$this->flock($operation)) {
8382
$this->logger->debug('could not acquire {lock_type} lock on {lock_file}', $log_data);
8483

85-
throw new Exception(
84+
throw new \Exception(
8685
'Could not acquire '.$lock_type.' lock on '.$this->lock_file
8786
);
8887

@@ -123,7 +122,7 @@ private function flock($operation)
123122
}
124123

125124
if (!is_resource($this->fh)) {
126-
throw new Exception('Could not open lock file '.$this->lock_file);
125+
throw new \Exception('Could not open lock file '.$this->lock_file);
127126
}
128127

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

0 commit comments

Comments
 (0)