for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Doctrine\Annotations\Type;
use function assert;
use function is_array;
use function sprintf;
/**
* @internal
*/
class MapType implements Type
{
/** @var ScalarType|UnionType */
private $keyType;
/** @var Type */
private $valueType;
public function __construct(Type $keyType, Type $valueType)
assert(
$keyType instanceof ScalarType || $keyType instanceof UnionType,
sprintf('Invalid key type %s', $keyType->describe())
);
$this->keyType = $keyType;
$this->valueType = $valueType;
}
public function getKeyType() : ScalarType
return $this->keyType;
return $this->keyType
Doctrine\Annotations\Type\UnionType
Doctrine\Annotations\Type\ScalarType
public function getValueType() : Type
return $this->valueType;
public function describe() : string
return sprintf('array<%s, %s>', $this->keyType->describe(), $this->valueType->describe());
* @param mixed $value
public function validate($value) : bool
if (! is_array($value)) {
return false;
foreach ($value as $key => $innerValue) {
if (! $this->keyType->validate($key)) {
if (! $this->valueType->validate($innerValue)) {
return true;