for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace One;
use One\Model\Tag;
class FactoryTag
{
public static function create(array $data): Tag
$data = self::validateArray($data);
$name = self::validateString(
(string) self::checkData($data, 'name', '')
);
$trending = (bool) self::checkData($data, 'trending', false);
false
string
$default
One\FactoryTag::checkData()
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
ignore-type
$trending = (bool) self::checkData($data, 'trending', /** @scrutinizer ignore-type */ false);
return self::createTag(
$name,
$trending
}
public static function createTag(
string $name,
bool $trending
): Tag {
return new Tag(
/**
* functionality to check whether a variable is set or not.
* @param mixed $key
* @param string $default
* @return mixed
*/
private static function checkData(array $data, $key, $default = '')
return $data[$key] ?? $default;
* functionality validity for array variables
private static function validateArray(array $var): array
if (gettype($var) === 'array') {
return $var;
throw new \Exception('The variable type must Array :');
* functionality validity for string variables
private static function validateString(String $var): String
if (gettype($var) === 'string') {
throw new \Exception('The variable type must String :' . $var);