@template T as bool

@param scalar|array|object|null $value

@psalm-param class-string<DaftObject> $class_name
178053
public static function ExpectRetrievedValueIsBoolish(
        string $property,
        $value,
        string $class_name
    ) : bool {
        if ('1' === $value || 1 === $value) {
            return true;
        } elseif ('0' === $value || 0 === $value) {
            return false;
        }

        /**
        * @psalm-var T
        */
        $value = static::MaybeThrowIfNotType($property, $value, $class_name, 'boolean');

        return $value;
    }
1349406
final protected function checkParameterType($value): void
    {
        if (\is_array($value)) {
            foreach ($value as $val) {
                $this->checkParameterType($val);
            }
        } elseif ($value !== null && !\is_scalar($value)) {
            throw new InvalidScalarParameterException(\sprintf(
                'Class %s can only accept scalar payload parameters, %s given',
                self::class,
                \is_object($value) ? \get_class($value) : \gettype($value)
            ));
        }
    }
367383
public static function ExpectRetrievedValueIsString(
        string $property,
        $value,
        string $class_name
    ) : string {
        /**
        * @psalm-var T
        */
        $value = static::MaybeThrowIfNotType($property, $value, $class_name, 'string');

        return $value;
    }
751779
public function HTML_QuickForm_radio($elementName=null, $elementLabel=null, $text=null, $value=null, $attributes=null) {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($elementName, $elementLabel, $text, $value, $attributes);
    }
383883
public function tag($name = null, $value = null) 
	{
		Argument::i()
			->test(1, 'string', 'null')
			->test(2, 'scalar', 'null');
			
		$field = Tag::i();
		
		if(!is_null($name)) {
			$field->setName($name);
		}
		
		if(!is_null($value)) {
			$field->setValue($value);
		}
		
		return $field;
	}
1111792
public function isValid($value, array $context = null)
    {
        $this->setValue($value);

        $token = $this->getToken();

        if (!$this->getLiteral() && $context !== null) {
            if (is_array($token)) {
                while (is_array($token)) {
                    $key = key($token);
                    if (!isset($context[$key])) {
                        break;
                    }
                    $context = $context[$key];
                    $token   = $token[$key];
                }
            }

            // if $token is an array it means the above loop didn't went all the way down to the leaf,
            // so the $token structure doesn't match the $context structure
            if (is_array($token) || !isset($context[$token])) {
                $token = $this->getToken();
            } else {
                $token = $context[$token];
            }
        }

        if ($token === null) {
            $this->error(self::MISSING_TOKEN);
            return false;
        }

        $strict = $this->getStrict();
        if (!($strict && ($value !== $token)) || (!$strict && ($value != $token))) {
            $this->error(self::SAME);
            return false;
        }

        return true;
    }
1008695
public function offsetSet($offset, $value)
    {
        //argument 1 must be scalar, null or bool
        Argument::i()->test(1, 'scalar', 'null', 'bool');

        if (!is_null($offset)) {
            if (in_array($offset, $this->setBoolKeys)) {
                $method = array_search($offset, $this->setBoolKeys);
                $this->call('set'.$method, array($value));
            }

            if (in_array($offset, $this->setIntegerKeys)) {
                $method = array_search($offset, $this->setIntegerKeys);
                $this->call('set'.$method, array($value));
            }

            if (in_array($offset, $this->setStringKeys)) {
                $method = array_search($offset, $this->setStringKeys);
                $this->call('set'.$method, array($value));
            }

            if (in_array($offset, $this->setArrayKeys)) {
                $method = array_search($offset, $this->setArrayKeys);
                $this->call('set'.$method, array($value));
            }

            if (in_array($offset, $this->setFileKeys)) {
                $method = array_search($offset, $this->setFileKeys);
                $this->call('set'.$method, array($value));
            }

            if (in_array($offset, $this->setCallbackKeys)) {
                $method = array_search($offset, $this->setCallbackKeys);
                $this->call('set'.$method, array($value));
            }
        }
    }
852801
public function checkType($value): bool
    {
        if (!$this->hasTypeDeclaration) {
            return true;
        }

        if ($this->isNullable && $value === null) {
            return true;
        }

        foreach ($this->types as $currentType) {
            $isValidType = $this->assertTypeEquals($currentType, $value);

            if ($isValidType) {
                return true;
            }
        }

        $type = \gettype($value);

        $expectedTypes = \implode('|', $this->getTypes());

        throw new \InvalidArgumentException("Invalid type: expected {$this->name} to be of type {{$expectedTypes}}, instead got value `" . \print_r($value, true) . "` with type {{$type}}.");
    }
1090320
public function value($value = NULL) {
        if($value == NULL) {
            return false;
        }
        
        $o = explode('.',$value);
        $data = $this->request->data;
        return $data[$o[0]][$o[1]][$o[2]];
    }
228804
public static function isInstanceOf($value, $class, $message = null)
    {
        if (!$value instanceof $class) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected instance of %2$s, but got %s',
                Helper::typeToString($value),
                $class
            ));
        }
    }
52744
public static function isNullOrScalar($value, $message = null)
    {
        if (!is_null($value) && !is_scalar($value)) {
            throw new InvalidArgumentException(sprintf(
                $message ?: 'Expected null or scalar, but got %s',
                Helper::typeToString($value)
            ));
        }
    }
753816
public static function ExpectRetrievedValueIsIntish(
        string $property,
        $value,
        string $class_name
    ) : int {
        if (is_string($value) && ctype_digit($value)) {
            $value = (int) $value;
        }

        /**
        * @psalm-var T
        */
        $value = static::MaybeThrowIfNotType($property, $value, $class_name, 'integer');

        return $value;
    }
1105397
@Override
    public String convertTo(final Object value) {
        if (value == null) return "null";
        return convertTo(value.getClass(), value);
    }
979822
public Object parse(String value, Class type)
    {
        if (StringUtil.isBlank(value))
        {
            return null;
        }

        return doConvert(value.trim(), type);
    }
1067623
public static function create(
        $value,
        array $php_version = null,
        array $template_type_map = []
    ) {
        switch ($value) {
            case 'int':
                return new TInt();

            case 'float':
                return new TFloat();

            case 'string':
                return new TString();

            case 'bool':
                return new TBool();

            case 'void':
                if ($php_version === null
                    || ($php_version[0] > 7)
                    || ($php_version[0] === 7 && $php_version[1] >= 1)
                ) {
                    return new TVoid();
                }

                break;

            case 'array-key':
                return new TArrayKey();

            case 'iterable':
                if ($php_version === null
                    || ($php_version[0] > 7)
                    || ($php_version[0] === 7 && $php_version[1] >= 1)
                ) {
                    return new TIterable();
                }

                break;

            case 'never-return':
            case 'never-returns':
            case 'no-return':
                return new TNever();

            case 'object':
                if ($php_version === null
                    || ($php_version[0] > 7)
                    || ($php_version[0] === 7 && $php_version[1] >= 2)
                ) {
                    return new TObject();
                }

                break;

            case 'callable':
                return new TCallable();

            case 'array':
                return new TArray([new Union([new TArrayKey]), new Union([new TMixed])]);

            case 'non-empty-array':
                return new TNonEmptyArray([new Union([new TMixed]), new Union([new TMixed])]);

            case 'resource':
                return $php_version !== null ? new TNamedObject($value) : new TResource();

            case 'numeric':
                return $php_version !== null ? new TNamedObject($value) : new TNumeric();

            case 'true':
                return $php_version !== null ? new TNamedObject($value) : new TTrue();

            case 'false':
                return $php_version !== null ? new TNamedObject($value) : new TFalse();

            case 'empty':
                return $php_version !== null ? new TNamedObject($value) : new TEmpty();

            case 'scalar':
                return $php_version !== null ? new TNamedObject($value) : new TScalar();

            case 'null':
                return $php_version !== null ? new TNamedObject($value) : new TNull();

            case 'mixed':
                return $php_version !== null ? new TNamedObject($value) : new TMixed();

            case 'class-string':
                return new TClassString();

            case 'callable-string':
                return new TCallableString();

            case 'numeric-string':
                return new TNumericString();

            case 'html-escaped-string':
                return new THtmlEscapedString();

            case '$this':
                return new TNamedObject('static');
        }

        if (strpos($value, '-') && substr($value, 0, 4) !== 'OCI-') {
            throw new \Psalm\Exception\TypeParseTreeException('no hyphens allowed');
        }

        if (is_numeric($value[0])) {
            throw new \Psalm\Exception\TypeParseTreeException('First character of type cannot be numeric');
        }

        if (isset($template_type_map[$value])) {
            $first_class = array_keys($template_type_map[$value])[0];
            return new TTemplateParam(
                $value,
                $template_type_map[$value][$first_class][0],
                $first_class
            );
        }

        return new TNamedObject($value);
    }
1271484
protected function castToBool($value, bool $nullable = true)
    {
        if (null === $value && $nullable) {
            return null;
        }

        return (bool) $value;
    }
518758
public static function factory($value)
    {
        
        if ($value instanceof self) {
            $value = $value->getValue();
        }
        
        $value = static::filter($value);
        
        if (!is_scalar($value)) {
            throw new ErrorException("A value object must be created from a scalar value!");
        }
        
        $classname = get_called_class();
        
        if (!isset(self::$instances[$classname])) {
            self::$instances[$classname] = array();
        }
    
        // lazy load the value-object
        if (!isset(self::$instances[$classname][$value])) {
            if (func_num_args()>1) {
                // construct value-object with more then the pure scalar value
                // (not really correct in terms of value-objects, but sometimes needed)
                $arguments = func_get_args();
                $reflection = new \ReflectionClass($classname);
                self::$instances[$classname][$value] = $reflection->newInstanceArgs($arguments);
                
            } else {
                self::$instances[$classname][$value] = new static($value);
            }
        }
    
        return self::$instances[$classname][$value];
    }