Browse Source

post code-review minor fixes

Olivier Massot 4 years ago
parent
commit
2cbc402220

+ 28 - 13
src/ApiResources/Dolibarr/DolibarrAccount.php

@@ -5,6 +5,9 @@ namespace App\ApiResources\Dolibarr;
 
 use ApiPlatform\Core\Annotation\ApiProperty;
 use ApiPlatform\Core\Annotation\ApiResource;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\Common\Collections\Collection;
+use JetBrains\PhpStorm\Pure;
 use Symfony\Component\Serializer\Annotation\Groups;
 
 /**
@@ -57,22 +60,29 @@ class DolibarrAccount
      * Contract and services currently active
      */
     #[Groups('dolibarr_get')]
-    private ?object $contract = null;
+    private ?DolibarrContract $contract = null;
 
     /**
      * Last bills
      */
     #[Groups('dolibarr_get')]
-    private array $bills = [];
+    private Collection $bills;
+
+    #[Pure]
+    public function __construct()
+    {
+        $this->bills = new ArrayCollection();
+    }
 
     public function getOrganizationId(): int
     {
         return $this->organizationId;
     }
 
-    public function setOrganizationId(int $organizationId): void
+    public function setOrganizationId(int $organizationId): self
     {
         $this->organizationId = $organizationId;
+        return $this;
     }
 
     public function getSocId(): int
@@ -80,9 +90,10 @@ class DolibarrAccount
         return $this->socId;
     }
 
-    public function setSocId(int $socId): void
+    public function setSocId(int $socId): self
     {
         $this->socId = $socId;
+        return $this;
     }
 
     public function getClientNumber(): string
@@ -90,9 +101,10 @@ class DolibarrAccount
         return $this->clientNumber;
     }
 
-    public function setClientNumber(string $clientNumber): void
+    public function setClientNumber(string $clientNumber): self
     {
         $this->clientNumber = $clientNumber;
+        return $this;
     }
 
     public function getProduct(): string
@@ -100,9 +112,10 @@ class DolibarrAccount
         return $this->product;
     }
 
-    public function setProduct(string $product): void
+    public function setProduct(string $product): self
     {
         $this->product = $product;
+        return $this;
     }
 
     public function getContract(): ?object
@@ -110,24 +123,26 @@ class DolibarrAccount
         return $this->contract;
     }
 
-    public function setContract(?object $contract): void
+    public function setContract(?object $contract): self
     {
         $this->contract = $contract;
+        return $this;
     }
 
-    public function getBills(): array
+    public function getBills(): Collection
     {
         return $this->bills;
     }
 
-    public function setBills(array $bills): void
+    public function addBill(DolibarrBill $bill): self
     {
-        $this->bills = $bills;
+        $this->bills[] = $bill;
+        return $this;
     }
 
-    public function addBill(DolibarrBill $bill): void
+    public function removeBill(DolibarrBill $bill): self
     {
-        $this->bills[] = $bill;
+        $this->bills->removeElement($bill);
+        return $this;
     }
-
 }

+ 13 - 34
src/ApiResources/Dolibarr/DolibarrBill.php

@@ -10,18 +10,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
 /**
  * Bill of a society, retrieved from dolibarr
  */
-#[ApiResource(
-    collectionOperations: [
-        'get' => [
-            'method' => 'GET',
-            'path' => '/dolibarr/bills/{socId}',
-            'requirements' => ['socId' => '\d+'],
-            'normalization_context' => [
-                'groups' => ['dolibarr_get']
-            ]
-        ],
-    ]
-)]
+#[ApiResource]
 class DolibarrBill
 {
     /**
@@ -37,12 +26,6 @@ class DolibarrBill
     #[Groups('dolibarr_get')]
     private string $ref;
 
-    /**
-     * Id of the society
-     */
-    #[Groups('dolibarr_get')]
-    private int $socId;
-
     /**
      * Date of the bill
      */
@@ -72,9 +55,10 @@ class DolibarrBill
         return $this->id;
     }
 
-    public function setId(int $id): void
+    public function setId(int $id): self
     {
         $this->id = $id;
+        return $this;
     }
 
     public function getRef(): string
@@ -82,19 +66,10 @@ class DolibarrBill
         return $this->ref;
     }
 
-    public function setRef(string $ref): void
+    public function setRef(string $ref): self
     {
         $this->ref = $ref;
-    }
-
-    public function getSocId(): int
-    {
-        return $this->socId;
-    }
-
-    public function setSocId(int $socId): void
-    {
-        $this->socId = $socId;
+        return $this;
     }
 
     public function getDate(): \DateTime
@@ -102,9 +77,10 @@ class DolibarrBill
         return $this->date;
     }
 
-    public function setDate(\DateTime $date): void
+    public function setDate(\DateTime $date): self
     {
         $this->date = $date;
+        return $this;
     }
 
     /**
@@ -118,9 +94,10 @@ class DolibarrBill
     /**
      * @param float $taxExcludedAmount
      */
-    public function setTaxExcludedAmount(float $taxExcludedAmount): void
+    public function setTaxExcludedAmount(float $taxExcludedAmount): self
     {
         $this->taxExcludedAmount = $taxExcludedAmount;
+        return $this;
     }
 
     /**
@@ -134,9 +111,10 @@ class DolibarrBill
     /**
      * @param float $taxIncludedAmount
      */
-    public function setTaxIncludedAmount(float $taxIncludedAmount): void
+    public function setTaxIncludedAmount(float $taxIncludedAmount): self
     {
         $this->taxIncludedAmount = $taxIncludedAmount;
+        return $this;
     }
 
     public function getPaid(): bool
@@ -144,9 +122,10 @@ class DolibarrBill
         return $this->paid;
     }
 
-    public function setPaid(bool $paid): void
+    public function setPaid(bool $paid): self
     {
         $this->paid = $paid;
+        return $this;
     }
 
 }

+ 22 - 20
src/ApiResources/Dolibarr/DolibarrContract.php

@@ -5,23 +5,15 @@ namespace App\ApiResources\Dolibarr;
 
 use ApiPlatform\Core\Annotation\ApiProperty;
 use ApiPlatform\Core\Annotation\ApiResource;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\Common\Collections\Collection;
+use JetBrains\PhpStorm\Pure;
 use Symfony\Component\Serializer\Annotation\Groups;
 
 /**
  * Contract of a society, retrieved from dolibarr
  */
-#[ApiResource(
-    itemOperations: [
-        'get' => [
-            'method' => 'GET',
-            'path' => '/dolibarr/contract/{ref}',
-            'requirements' => ['socId' => '\d+'],
-            'normalization_context' => [
-                'groups' => ['dolibarr_get']
-            ]
-        ],
-    ]
-)]
+#[ApiResource]
 class DolibarrContract
 {
     /**
@@ -41,16 +33,23 @@ class DolibarrContract
      * Lines (services) included in the current contract
      */
     #[Groups('dolibarr_get')]
-    private array $lines = [];
+    private Collection $lines;
+
+    #[Pure]
+    public function __construct()
+    {
+        $this->lines = new ArrayCollection();
+    }
 
     public function getRef(): string
     {
         return $this->ref;
     }
 
-    public function setRef(string $ref): void
+    public function setRef(string $ref): self
     {
         $this->ref = $ref;
+        return $this;
     }
 
     public function getSocId(): int
@@ -58,23 +57,26 @@ class DolibarrContract
         return $this->socId;
     }
 
-    public function setSocId(int $socId): void
+    public function setSocId(int $socId): self
     {
         $this->socId = $socId;
+        return $this;
     }
 
-    public function getLines(): array
+    public function getLines(): Collection
     {
         return $this->lines;
     }
 
-    public function setLines(array $lines): void
+    public function addLine(DolibarrContractLine $line): self
     {
-        $this->lines = $lines;
+        $this->lines[] = $line;
+        return $this;
     }
 
-    public function addLine(object $line): void
+    public function removeBill(DolibarrContractLine $line): self
     {
-        $this->lines[] = $line;
+        $this->lines->removeElement($line);
+        return $this;
     }
 }

+ 13 - 18
src/ApiResources/Dolibarr/DolibarrContractLine.php

@@ -10,18 +10,7 @@ use Symfony\Component\Serializer\Annotation\Groups;
 /**
  *  Lines (services) included in a society contract, as retrieved from dolibarr
  */
-#[ApiResource(
-    collectionOperations: [
-        'get' => [
-            'method' => 'GET',
-            'path' => '/dolibarr/contract-lines/{contractId}',
-            'requirements' => ['contractId' => '\d+'],
-            'normalization_context' => [
-                'groups' => ['dolibarr_get']
-            ]
-        ],
-    ]
-)]
+#[ApiResource]
 class DolibarrContractLine
 {
     #[ApiProperty(identifier: true)]
@@ -63,9 +52,10 @@ class DolibarrContractLine
         return $this->id;
     }
 
-    public function setId(int $id): void
+    public function setId(int $id): self
     {
         $this->id = $id;
+        return $this;
     }
 
     public function getContractId(): int
@@ -73,9 +63,10 @@ class DolibarrContractLine
         return $this->contractId;
     }
 
-    public function setContractId(int $contractId): void
+    public function setContractId(int $contractId): self
     {
         $this->contractId = $contractId;
+        return $this;
     }
 
     public function getServiceRef(): string
@@ -83,9 +74,10 @@ class DolibarrContractLine
         return $this->serviceRef;
     }
 
-    public function setServiceRef(string $serviceRef): void
+    public function setServiceRef(string $serviceRef): self
     {
         $this->serviceRef = $serviceRef;
+        return $this;
     }
 
     public function getServiceLabel(): string
@@ -93,9 +85,10 @@ class DolibarrContractLine
         return $this->serviceLabel;
     }
 
-    public function setServiceLabel(string $serviceLabel): void
+    public function setServiceLabel(string $serviceLabel): self
     {
         $this->serviceLabel = $serviceLabel;
+        return $this;
     }
 
     public function getDateStart(): \DateTime
@@ -103,9 +96,10 @@ class DolibarrContractLine
         return $this->dateStart;
     }
 
-    public function setDateStart(\DateTime $dateStart): void
+    public function setDateStart(\DateTime $dateStart): self
     {
         $this->dateStart = $dateStart;
+        return $this;
     }
 
     public function isDateEnd(): \DateTime
@@ -113,8 +107,9 @@ class DolibarrContractLine
         return $this->dateEnd;
     }
 
-    public function setDateEnd(\DateTime $dateEnd): void
+    public function setDateEnd(\DateTime $dateEnd): self
     {
         $this->dateEnd = $dateEnd;
+        return $this;
     }
 }

+ 0 - 7
src/ApiResources/Mobyt/MobytUserStatus.php

@@ -17,34 +17,27 @@ use Symfony\Component\Serializer\Annotation\Groups;
             'method' => 'GET',
             'path' => '/mobyt/status/{organizationId}',
             'requirements' => ['organizationId' => '\d+'],
-            'normalization_context' => [
-                'groups' => ['mobyt_get']
-            ],
         ],
     ]
 )]
 class MobytUserStatus
 {
     #[ApiProperty(identifier: true)]
-    #[Groups('mobyt_get')]
     private int $organizationId;
 
     /**
      * Is there a Mobyt account active for this user
      */
-    #[Groups('mobyt_get')]
     private bool $active = false;
 
     /**
      * Amount of sms remaining
      */
-    #[Groups('mobyt_get')]
     private int $amount = 0;
 
     /**
      * Money remaining
      */
-    #[Groups('mobyt_get')]
     private float $money = 0;
 
     public function getOrganizationId(): int