for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Application\Traits;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\ORM\Mapping as ORM;
/**
* Trait for all objects with an IBAN (international bank account number)
*/
trait HasIban
{
* @var string
*
* @ORM\Column(type="string", length=34, unique=true, nullable=true)
private $iban;
* Set the IBAN (international bank account number)
* @param string $iban
* @throws InvalidArgumentException
public function setIban(string $iban): void
$validator = new \Zend\Validator\Iban(['country_code' => 'CH']);
if (empty($iban)) {
$this->iban = null;
} elseif ($validator->isValid($iban)) {
$this->iban = $iban;
} else {
throw new InvalidArgumentException('Invalid IBAN number');
}
* Get the IBAN (international bank account number)
* @return string
public function getIban(): string
return (string) $this->iban;