Skip to content

Commit 32e84d3

Browse files
committed
fix: Move skip validation in dedicated class
1 parent ff9acc7 commit 32e84d3

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Util/SkipValidation.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Loki\Components\Util;
4+
5+
class SkipValidation
6+
{
7+
private bool $skipValidation = false;
8+
9+
public function isSkipValidation(): bool
10+
{
11+
return $this->skipValidation;
12+
}
13+
14+
public function setSkipValidation(bool $skipValidation): void
15+
{
16+
$this->skipValidation = $skipValidation;
17+
}
18+
}

Validator/RequiredValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
use Loki\Components\Component\ComponentInterface;
66
use Loki\Components\Util\Ajax;
77
use Loki\Components\Util\IsEmpty;
8-
use Magento\Framework\App\RequestInterface;
8+
use Loki\Components\Util\SkipValidation;
99

1010
class RequiredValidator implements ValidatorInterface
1111
{
1212
public function __construct(
1313
private readonly IsEmpty $isEmpty,
14-
private readonly RequestInterface $request,
1514
private readonly Ajax $ajax,
15+
private readonly SkipValidation $skipValidation
1616
) {
1717
}
1818

@@ -22,8 +22,8 @@ public function validate(mixed $value, ?ComponentInterface $component = null): b
2222
return true;
2323
}
2424

25-
if (true === $this->request->getParam('skip_validation')) {
26-
return true; // @todo: Set this flag in an internal place only
25+
if ($this->skipValidation->isSkipValidation()) {
26+
return true;
2727
}
2828

2929
if ($this->isEmpty->execute($component, $value)) {

0 commit comments

Comments
 (0)