Jacek Kowalski
2023-06-14 ebf0b71cb81db506b018a1da12edea635f605937
Add parameter/property type hints
8 files modified
90 ■■■■ changed files
src/ContractorSynchronizer.php 6 ●●●● patch | view | raw | blame | history
src/InvoiceSynchronizer.php 14 ●●●● patch | view | raw | blame | history
src/PaymentSynchronizer.php 12 ●●●● patch | view | raw | blame | history
src/Synchronizer.php 16 ●●●● patch | view | raw | blame | history
src/UcrmAttributes.php 12 ●●●● patch | view | raw | blame | history
src/UcrmHelper.php 22 ●●●● patch | view | raw | blame | history
src/UcrmPaymentMethods.php 6 ●●●● patch | view | raw | blame | history
src/wFirmaApiFactory.php 2 ●●● patch | view | raw | blame | history
src/ContractorSynchronizer.php
@@ -2,11 +2,11 @@
namespace SIPL\UCRM\wFirma;
use \Webit\WFirmaSDK\Contractors as Contractors;
use \Webit\WFirmaSDK\Payments as Payments;
use Webit\WFirmaSDK\Contractors as Contractors;
use Webit\WFirmaSDK\Payments as Payments;
class ContractorSynchronizer extends Synchronizer {
    function synchronize(int $ucrmClientId) {
    function synchronize(int $ucrmClientId): bool {
        $crm = $this->helper->getApi();
        $wFirmaContractors = $this->wfirma->contractorsApi();
src/InvoiceSynchronizer.php
@@ -2,12 +2,12 @@
namespace SIPL\UCRM\wFirma;
use \Webit\WFirmaSDK\Contractors as Contractors;
use \Webit\WFirmaSDK\Invoices as Invoices;
use \Webit\WFirmaSDK\Payments as Payments;
use Webit\WFirmaSDK\Contractors as Contractors;
use Webit\WFirmaSDK\Invoices as Invoices;
use Webit\WFirmaSDK\Payments as Payments;
class InvoiceSynchronizer extends Synchronizer {
    function getContractorId($clientId, $synchronize = TRUE) {
    protected function getContractorId($clientId, $synchronize = TRUE): ?Contractors\ContractorId {
        if ($synchronize) {
            $synchronizer = new ContractorSynchronizer($this->wfirma, $this->helper);
            $synchronizer->synchronize($clientId);
@@ -29,7 +29,7 @@
        return Contractors\ContractorId::create($wFirmaId);
    }
    function getTaxes() {
    protected function getTaxes(): array {
        $crm = $this->helper->getApi();
        $taxesData = $crm->get('/taxes');
@@ -40,14 +40,14 @@
        return $taxes;
    }
    function compareInvoicesContent(Invoices\InvoicesContent $c1, Invoices\InvoicesContent $c2) {
    protected function compareInvoicesContent(Invoices\InvoicesContent $c1, Invoices\InvoicesContent $c2): int {
        return
            [$c1->name(), $c1->unit(), $c1->count(), $c1->price(), $c1->vat(), $c1->discount()]
            <=>
            [$c2->name(), $c2->unit(), $c2->count(), $c2->price(), $c2->vat(), $c2->discount()];
    }
    function synchronize(int $ucrmInvoiceId) {
    function synchronize(int $ucrmInvoiceId): bool {
        $crm = $this->helper->getApi();
        $wFirmaInvoices = $this->wfirma->invoicesApi();
src/PaymentSynchronizer.php
@@ -2,8 +2,8 @@
namespace SIPL\UCRM\wFirma;
use \Webit\WFirmaSDK\Invoices as Invoices;
use \Webit\WFirmaSDK\Payments as Payments;
use Webit\WFirmaSDK\Invoices as Invoices;
use Webit\WFirmaSDK\Payments as Payments;
class PaymentSynchronizer extends Synchronizer {
    protected $ucrmMainDir;
@@ -14,17 +14,17 @@
        $backtrace = debug_backtrace();
        $backtrace = end($backtrace);
        // (...)/web/_plugins/wfirma/public.php
        $this->ucrmMainDir = dirname(dirname(dirname(dirname($backtrace['file']))));
        $this->ucrmMainDir = dirname($backtrace['file'], 4);
    }
    function comparePayment(Payments\Payment $p1, Payments\Payment $p2) {
    function comparePayment(Payments\Payment $p1, Payments\Payment $p2): int {
        return
            [$p1->objectName(), $p1->objectId(), $p1->amount()->value(), $p1->date()->format('Y-m-d'), $p1->paymentMethod()]
            <=>
            [$p2->objectName(), $p2->objectId(), $p2->amount()->value(), $p2->date()->format('Y-m-d'), $p2->paymentMethod()];
    }
    function synchronize(int $ucrmPaymentId) {
    function synchronize(int $ucrmPaymentId): bool {
        $crm = $this->helper->getApi();
        $wFirmaPaymentsApi = $this->wfirma->paymentsApi();
@@ -171,7 +171,7 @@
        return $changed;
    }
    function delete(array $paymentData) {
    function delete(array $paymentData): bool {
        $wFirmaPaymentsApi = $this->wfirma->paymentsApi();
        $paymentAttributeId = $this->helper->getAttributes()->getIdForCode('payment');
src/Synchronizer.php
@@ -3,19 +3,27 @@
namespace SIPL\UCRM\wFirma;
abstract class Synchronizer {
    protected $wfirma;
    protected $helper;
    protected \Webit\WFirmaSDK\Entity\ModuleApiFactory $wfirma;
    protected UcrmHelper $helper;
    function __construct(\Webit\WFirmaSDK\Entity\ModuleApiFactory $wFirmaApi, UcrmHelper $ucrmHelper) {
        $this->wfirma = $wFirmaApi;
        $this->helper = $ucrmHelper;
    }
    public function synchronize(int $entityId) {
    /**
     * @param int $entityId
     * @return bool TRUE if anything was modified, FALSE otherwise
     */
    public function synchronize(int $entityId): bool {
        return FALSE;
    }
    public function delete(array $entity) {
    /**
     * @param array $entity
     * @return bool TRUE if anything was deleted, FALSE otherwise
     */
    public function delete(array $entity): bool {
        return FALSE;
    }
}
src/UcrmAttributes.php
@@ -3,10 +3,10 @@
namespace SIPL\UCRM\wFirma;
class UcrmAttributes {
    protected $attributesFile;
    protected $api;
    protected string $attributesFile;
    protected \Ubnt\UcrmPluginSdk\Service\UcrmApi $api;
    protected static $definition = [
    protected static array $definition = [
        'wFirma Customer ID' => [
            'code' => 'client',
            'type' => 'client',
@@ -20,7 +20,7 @@
            'type' => 'payment',
        ],
    ];
    protected $ids = [];
    protected array $ids = [];
    function __construct(UcrmHelper $ucrmHelper) {
        $this->attributesFile = $ucrmHelper->getRootDirectory() . '/data/attributes.json';
@@ -41,7 +41,7 @@
        return $this->ids[$attributeCode];
    }
    function updateMapping() {
    function updateMapping(): bool {
        $attributes = $this->api->get('/custom-attributes');
        foreach ($attributes as $attribute) {
            $data = self::$definition[$attribute['name']] ?? NULL;
@@ -71,7 +71,7 @@
        return $changed;
    }
    function saveMapping() {
    function saveMapping(): void {
        if (!is_dir(dirname($this->attributesFile))) {
            mkdir(dirname($this->attributesFile));
        }
src/UcrmHelper.php
@@ -3,10 +3,10 @@
namespace SIPL\UCRM\wFirma;
class UcrmHelper {
    protected $rootDirectory;
    protected $api = NULL;
    protected $attributes = NULL;
    protected $paymentMethods = NULL;
    protected string $rootDirectory;
    protected ?\Ubnt\UcrmPluginSdk\Service\UcrmApi $api = NULL;
    protected ?UcrmAttributes $attributes = NULL;
    protected ?UcrmPaymentMethods $paymentMethods = NULL;
    protected $config = NULL;
    protected $event = NULL;
@@ -17,32 +17,32 @@
        $this->rootDirectory = $rootDirectory;
    }
    function getRootDirectory() {
    function getRootDirectory(): string {
        return $this->rootDirectory;
    }
    function getApi() {
    function getApi(): \Ubnt\UcrmPluginSdk\Service\UcrmApi {
        if ($this->api === NULL) {
            $this->api = \Ubnt\UcrmPluginSdk\Service\UcrmApi::create($this->rootDirectory);
        }
        return $this->api;
    }
    function getAttributes() {
    function getAttributes(): UcrmAttributes {
        if ($this->attributes === NULL) {
            $this->attributes = new UcrmAttributes($this);
        }
        return $this->attributes;
    }
    function getPaymentMethods() {
    function getPaymentMethods(): UcrmPaymentMethods {
        if ($this->paymentMethods === NULL) {
            $this->paymentMethods = new UcrmPaymentMethods($this);
        }
        return $this->paymentMethods;
    }
    function getConfig() {
    function getConfig(): array {
        if ($this->config === NULL) {
            $configManager = \Ubnt\UcrmPluginSdk\Service\PluginConfigManager::create($this->rootDirectory);
            $this->config = $configManager->loadConfig();
@@ -50,12 +50,12 @@
        return $this->config;
    }
    function getVersion() {
    function getVersion(): string {
        $response = $this->getApi()->get('/version');
        return $response['version'];
    }
    function getCurrentEvent() {
    function getCurrentEvent(): array {
        if ($this->event === NULL) {
            try {
                if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
src/UcrmPaymentMethods.php
@@ -3,8 +3,8 @@
namespace SIPL\UCRM\wFirma;
class UcrmPaymentMethods {
    protected $api;
    protected static $definition = [
    protected \Ubnt\UcrmPluginSdk\Service\UcrmApi $api;
    protected static array $definition = [
        'Credit card' => '',
        'Compensation' => '',
    ];
@@ -21,7 +21,7 @@
        return self::$definition[$method];
    }
    function update() {
    function update(): void {
        $methods = $this->api->get('/payment-methods');
        foreach ($methods as $method) {
            if (isset(self::$definition[$method['name']])) {
src/wFirmaApiFactory.php
@@ -3,7 +3,7 @@
namespace SIPL\UCRM\wFirma;
class wFirmaApiFactory {
    protected $ucrmHelper;
    protected UcrmHelper $ucrmHelper;
    function __construct(UcrmHelper $ucrmHelper) {
        $this->ucrmHelper = $ucrmHelper;