for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Genkgo\Mail\Header;
final class HeaderName
{
/**
* @var string
*/
private $name;
* @param string $name
public function __construct(string $name)
$this->assert($name);
$this->name = $name;
}
* @return bool
public function is(string $name): bool
return \strcasecmp($this->name, $name) === 0;
private function assert(string $name)
if ($this->validate($name) === false) {
throw new \InvalidArgumentException(
'Invalid header name ' . $name . '. Wrong characters used or length too long (max 74)'
);
private function validate(string $name): bool
$tot = \strlen($name);
if ($tot > 74) {
return false;
for ($i = 0; $i < $tot; $i += 1) {
$ord = \ord($name[$i]);
if ($ord < 33 || $ord > 126 || $ord === 58) {
return true;
* @return string
public function __toString(): string
return $this->name;