public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$this->isHtml($attributes)) { return $attributes; } $document = $this->reader->read($response->body()); try { $meta = (new Elements('meta'))((new Head())($document))->filter(function (ElementInterface $meta) : bool { return $meta->attributes()->contains('name') && $meta->attributes()->contains('content'); })->filter(function (ElementInterface $meta) : bool { $name = $meta->attributes()->get('name')->value(); return (string) (new Str($name))->toLower() === 'theme-color'; }); } catch (ElementNotFoundException $e) { return $attributes; } if ($meta->size() !== 1) { return $attributes; } try { $colour = Colour::fromString($meta->current()->attributes()->get('content')->value()); } catch (ExceptionInterface $e) { return $attributes; } return $attributes->put(self::key(), new Attribute(self::key(), $colour, $this->clock->now()->elapsedSince($start)->milliseconds())); }