src/Entity/BankAccount.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Doctrine\ORM\Mapping\JoinColumn;
  5. use Doctrine\ORM\Mapping\ManyToOne;
  6. use JMS\Serializer\Annotation\Groups;
  7. /**
  8.  * @ORM\Table("BankAccount")
  9.  *
  10.  * @ORM\Entity(repositoryClass="App\Repository\BankAccountRepository")
  11.  */
  12. class BankAccount
  13. {
  14.     /**
  15.      * @Groups({"bankaccount", "accountindex"})
  16.      *
  17.      * @ORM\Id()
  18.      *
  19.      * @ORM\GeneratedValue()
  20.      *
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @Groups({"bankaccount", "accountindex"})
  26.      *
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $account_holder;
  30.     /**
  31.      * @Groups({"bankaccount", "accountindex"})
  32.      *
  33.      * @ORM\Column(type="string", length=255, nullable=true)
  34.      */
  35.     private $account_number;
  36.     /**
  37.      * @Groups({"bankaccount", "accountindex"})
  38.      *
  39.      * @ORM\Column(type="string", length=255, nullable=true)
  40.      */
  41.     private $bank_code;
  42.     /**
  43.      * @ManyToOne(targetEntity="App\Entity\Account", cascade={"persist"})
  44.      *
  45.      * @JoinColumn(name="account_id", referencedColumnName="id", onDelete="SET NULL")
  46.      */
  47.     private $account;
  48.     /**
  49.      * @Groups({"accountindex"})
  50.      *
  51.      * @ORM\Column(type="datetime")
  52.      */
  53.     private $created_at;
  54.     public function __construct()
  55.     {
  56.         $this->setCreatedAt(new \DateTime());
  57.     }
  58.     public function getId()
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getAccountHolder(): ?string
  63.     {
  64.         return $this->account_holder;
  65.     }
  66.     public function setAccountHolder(?string $account_holder): self
  67.     {
  68.         $this->account_holder $account_holder;
  69.         return $this;
  70.     }
  71.     public function getAccountNumber(): ?string
  72.     {
  73.         return $this->account_number;
  74.     }
  75.     public function isSameAccountNumber(?string $accountNumber): bool
  76.     {
  77.         return null !== $this->account_number
  78.             && (str_replace(' ''', (string) $this->account_number) === str_replace(' ''', (string) $accountNumber));
  79.     }
  80.     public function setAccountNumber(?string $account_number): self
  81.     {
  82.         if (!$this->isSameAccountNumber($account_number)) {
  83.             $this->bank_code null;
  84.         }
  85.         $this->account_number $account_number;
  86.         return $this;
  87.     }
  88.     public function getBankCode(): ?string
  89.     {
  90.         return $this->bank_code;
  91.     }
  92.     public function setBankCode(?string $bank_code): self
  93.     {
  94.         $this->bank_code $bank_code;
  95.         return $this;
  96.     }
  97.     public function getAccount(): ?Account
  98.     {
  99.         return $this->account;
  100.     }
  101.     public function setAccount(?Account $account): self
  102.     {
  103.         $this->account $account;
  104.         return $this;
  105.     }
  106.     public function getCreatedAt(): ?\DateTimeInterface
  107.     {
  108.         return $this->created_at;
  109.     }
  110.     public function setCreatedAt(\DateTimeInterface $created_at): self
  111.     {
  112.         $this->created_at $created_at;
  113.         return $this;
  114.     }
  115.     public function isAccountNumberProbablyIban(): bool
  116.     {
  117.         return === preg_match('#^([A-Z]{2}\s*\d{2}\s*\d{2})#'$this->account_number);
  118.     }
  119.     public function hasChangedMainFields(?BankAccount $ba): bool
  120.     {
  121.         if (null === $ba) {
  122.             return null !== $this->getAccountHolder()
  123.                 || null !== $this->getAccountNumber()
  124.                 || null !== $this->getBankCode();
  125.         }
  126.         return
  127.             $this->getAccountHolder() !== $ba->getAccountHolder()
  128.             || $this->getAccountNumber() !== $ba->getAccountNumber()
  129.             || $this->getBankCode() !== $ba->getBankCode();
  130.     }
  131.     public function isBankAccountDE(): bool
  132.     {
  133.         return null !== $this->account_number && === stripos($this->account_number'de');
  134.     }
  135. }