Skip to content

Commit 84696d2

Browse files
committed
linting
1 parent 813db66 commit 84696d2

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

spec/TH/Lock/FileFactorySpec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class FileFactorySpec extends ObjectBehavior
1717
public function let()
1818
{
1919
$this->fs = new FileSystem;
20-
$this->lock_dir = $this->fs->path('/path/to/lock_dir');
20+
$this->lock_dir = $this->fs->path("/path/to/lock_dir");
2121

22-
$this->beConstructedWith($this->lock_dir, 'sha256');
22+
$this->beConstructedWith($this->lock_dir, "sha256");
2323
}
2424

2525
public function it_is_initializable()
@@ -30,6 +30,6 @@ public function it_is_initializable()
3030

3131
public function it_should_create_a_file_lock()
3232
{
33-
$this->create('some resource identifier')->shouldhaveType(FileLock::class);
33+
$this->create("some resource identifier")->shouldhaveType(FileLock::class);
3434
}
3535
}

spec/TH/Lock/FileLockSpec.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FileLockSpec extends ObjectBehavior
1616
public function let()
1717
{
1818
$this->fs = new FileSystem;
19-
$this->lock_file = $this->fs->path('/path/to/lock_file.lock');
19+
$this->lock_file = $this->fs->path("/path/to/lock_file.lock");
2020

2121
mkdir(dirname($this->lock_file), 0777, true);
2222

@@ -34,11 +34,11 @@ public function it_should_acquire_an_exclusive_lock()
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

40-
if (flock(fopen($this->lock_file, 'r'), LOCK_SH|LOCK_NB)) {
41-
throw new \Exception('Lock file was not exclusively locked');
40+
if (flock(fopen($this->lock_file, "r"), LOCK_SH|LOCK_NB)) {
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

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

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

@@ -66,15 +66,15 @@ public function it_should_release_a_lock()
6666
$this->acquire();
6767
$this->release();
6868

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

7474
public function it_should_throw_if_it_cannot_lock()
7575
{
7676
touch($this->lock_file);
77-
flock(fopen($this->lock_file, 'r'), LOCK_SH|LOCK_NB);
77+
flock(fopen($this->lock_file, "r"), LOCK_SH|LOCK_NB);
7878

7979
$this->shouldThrow()->duringAcquire();
8080
}
@@ -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

@@ -96,13 +96,13 @@ public function it_does_not_remove_its_lock_file_if_still_locked()
9696
$this->beConstructedWith($this->lock_file, FileLock::SHARED, FileLock::NON_BLOCKING, true);
9797

9898
touch($this->lock_file);
99-
flock(fopen($this->lock_file, 'r'), LOCK_SH|LOCK_NB);
99+
flock(fopen($this->lock_file, "r"), LOCK_SH|LOCK_NB);
100100

101101
$this->acquire();
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

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

125125
$this->release();

src/FileFactory.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,8 @@ public function create(
4242
if (!is_dir($this->lock_dir)) {
4343
mkdir($this->lock_dir, 0777, true);
4444
}
45-
46-
$path = $this->lock_dir.'/'.hash($this->hash_algo, serialize($resource)).'.lock';
47-
48-
$lock = new FileLock($path, $exclusive, $blocking, true, $this->logger);
49-
50-
return $lock;
45+
$hash = hash($this->hash_algo, serialize($resource));
46+
$path = "{$this->lock_dir}/$hash.lock";
47+
return new FileLock($path, $exclusive, $blocking, true, $this->logger);
5148
}
5249
}

src/FileLock.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function __construct(
5050
public function acquire()
5151
{
5252
if ($this->exclusive === FileLock::EXCLUSIVE) {
53-
$lock_type = 'exclusive';
53+
$lock_type = "exclusive";
5454
$operation = LOCK_EX;
5555
} else {
56-
$lock_type = 'shared';
56+
$lock_type = "shared";
5757
$operation = LOCK_SH;
5858
}
5959

@@ -74,20 +74,20 @@ public function acquire()
7474
private function tryAcquire($operation, $lock_type)
7575
{
7676
$log_data = [
77-
'lock_file' => $this->lock_file,
78-
'lock_type' => $lock_type
77+
"lock_file" => $this->lock_file,
78+
"lock_type" => $lock_type
7979
];
8080

8181
if (!$this->flock($operation)) {
82-
$this->logger->debug('could not acquire {lock_type} lock on {lock_file}', $log_data);
82+
$this->logger->debug("could not acquire {lock_type} lock on {lock_file}", $log_data);
8383

84-
throw new \Exception(
85-
'Could not acquire '.$lock_type.' lock on '.$this->lock_file
84+
throw new \RuntimeException(
85+
"Could not acquire $lock_type lock on {$this->lock_file}"
8686
);
8787

8888
}
8989

90-
$this->logger->debug('{lock_type} lock acquired on {lock_file}', $log_data);
90+
$this->logger->debug("{lock_type} lock acquired on {lock_file}", $log_data);
9191
}
9292

9393
public function release()
@@ -104,7 +104,7 @@ public function release()
104104
fclose($this->fh);
105105
$this->fh = null;
106106

107-
$this->logger->debug('{lock_type} lock released on {lock_file}', ['lock_file' => $this->lock_file]);
107+
$this->logger->debug("{lock_type} lock released on {lock_file}", ["lock_file" => $this->lock_file]);
108108
}
109109

110110
public function __destruct()
@@ -118,11 +118,11 @@ public function __destruct()
118118
private function flock($operation)
119119
{
120120
if ($this->fh === null) {
121-
$this->fh = fopen($this->lock_file, 'c');
121+
$this->fh = fopen($this->lock_file, "c");
122122
}
123123

124124
if (!is_resource($this->fh)) {
125-
throw new \Exception('Could not open lock file '.$this->lock_file);
125+
throw new \RuntimeException("Could not open lock file {$this->lock_file}");
126126
}
127127

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

0 commit comments

Comments
 (0)