for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Hryvinskyi\QuoteAddressValidator\Model\Validation;
use Hryvinskyi\QuoteAddressValidator\Model\ConfigInterface;
abstract class AbstractValidator implements \Hryvinskyi\QuoteAddressValidator\Model\ValidationInterface
{
/**
* @var ConfigInterface
*/
private $config;
public function __construct(ConfigInterface $config)
$this->config = $config;
}
* @return ConfigInterface
public function getConfig(): ConfigInterface
return $this->config;
* Check string for stop words
*
* @param string $string
* @param array $stopWords
* @return bool True if the string does not contain stop words
public function checkStringForStopWords(string $string, array $stopWords): bool
foreach ($stopWords as $stopWord) {
if (stripos($string, $stopWord) !== false) {
return false;
return true;
* Validate the value
* @param string $value
* @param string $pattern
* @return bool True if the value is valid
public function validate(string $value, string $pattern, array $stopWords): bool
switch ($this->getConfig()->getValidationType()) {
case 1: // Regex
return preg_match($pattern, $value) === 1;
break;
break
The break statement is not necessary if it is preceded for example by a return statement:
return
switch ($x) { case 1: return 'foo'; break; // This break is not necessary and can be left off. }
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.
case
case 2: // Stop words
return $this->checkStringForStopWords($value, $stopWords);
case 3: // Regex and stop words
return preg_match($pattern, $value) === 1 && $this->checkStringForStopWords($value, $stopWords);
* @inheritDoc
abstract public function execute(\Magento\Quote\Api\Data\AddressInterface $address): bool;
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.