Skip to content

Commit 6be3e36

Browse files
committed
better record (un)locking
1 parent b496e4d commit 6be3e36

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/AbraFlexi/lock.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,54 @@
2121
*/
2222
trait lock
2323
{
24+
/**
25+
* Check if record is locked.
26+
*
27+
* @throws \InvalidArgumentException if zamekK is not set
28+
*/
2429
public function locked(): bool
2530
{
2631
$lockValue = $this->getDataValue('zamekK');
27-
if(is_null($lockValue)){
28-
throw new \InvalidArgumentException('unset zamekK',1);
32+
33+
if (null === $lockValue) {
34+
throw new \InvalidArgumentException('unset zamekK', 1);
2935
}
30-
return $lockValue === 'zamek.otevreno';
36+
37+
return $lockValue !== 'zamek.otevreno';
3138
}
3239

40+
/**
41+
* Get lock type. Value of zamekK without "zamek."
42+
* Most common values are "otevreno" and "uzamceno".
43+
*
44+
* @throws \InvalidArgumentException if zamekK is not set
45+
*/
3346
public function getLockType(): string
3447
{
3548
$lockValue = $this->getDataValue('zamekK');
36-
if(is_null($lockValue)){
37-
throw new \InvalidArgumentException('unset zamekK',1);
49+
50+
if (null === $lockValue) {
51+
throw new \InvalidArgumentException('unset zamekK', 1);
3852
}
53+
3954
return str_replace('zamek.', '', $lockValue);
4055
}
4156

57+
/**
58+
* Locks the current record.
59+
*
60+
* @return bool true on success, false on failure
61+
*/
4262
public function lock(): bool
4363
{
44-
return $this->performAction('unlock');
64+
return $this->performAction('lock');
4565
}
4666

67+
/**
68+
* Unlocks the current record.
69+
*
70+
* @return bool true on success, false on failure
71+
*/
4772
public function unlock(): bool
4873
{
4974
return $this->performAction('unlock');

0 commit comments

Comments
 (0)