106b3d42517bb511600ac0e464d38498d5d53120..e9cd26454a3b0220477dc52e763b891d93e78401
2023-06-14 Jacek Kowalski
Release version 1.0
e9cd26 diff | tree
2023-06-14 Jacek Kowalski
Add parameter/property type hints
a708f0 diff | tree
2023-06-14 Jacek Kowalski
Fixes for UCRM 4.0
a23175 diff | tree
4 files modified
38 ■■■■ changed files
composer.json 6 ●●●● patch | view | raw | blame | history
manifest.json 4 ●●●● patch | view | raw | blame | history
src/HolidaySkipper.php 12 ●●●●● patch | view | raw | blame | history
src/UcrmHelper.php 16 ●●●● patch | view | raw | blame | history
composer.json
@@ -6,12 +6,12 @@
    },
    "config": {
        "platform": {
            "php": "7.3.26"
            "php": "8.1"
        }
    },
    "require": {
        "php": ">=7.3",
        "ubnt/ucrm-plugin-sdk": "^0.8.1",
        "php": ">=8.1",
        "ubnt/ucrm-plugin-sdk": "^0.9.0",
        "umulmrum/holiday": "^0.6.0"
    }
}
manifest.json
@@ -5,9 +5,9 @@
        "displayName": "Holidays skipper",
        "description": "Changes invoice due date if it is on a day off (holiday, weekend)",
        "url": "https://github.com/jacekkow/ucrm-holidays",
        "version": "0.1",
        "version": "1.0",
        "ucrmVersionCompliancy": {
            "min": "3.0.0-beta2",
            "min": "4.0.0",
            "max": null
        },
        "unmsVersionCompliancy": {
src/HolidaySkipper.php
@@ -8,15 +8,15 @@
use Umulmrum\Holiday\Model\HolidayList;
class HolidaySkipper {
    protected $helper;
    protected $skipDays = null;
    protected $holidays = null;
    protected UcrmHelper $helper;
    protected ?array $skipDays = null;
    protected ?HolidayList $holidays = null;
    function __construct(UcrmHelper $ucrmHelper) {
        $this->helper = $ucrmHelper;
    }
    protected function configure(array $years) {
    protected function configure(array $years): void {
        $config = $this->helper->getConfig();
        if ($this->skipDays === NULL) {
@@ -39,7 +39,7 @@
        }
    }
    function processInvoice(string $invoiceId) {
    function processInvoice(string $invoiceId): bool {
        $crm = $this->helper->getApi();
        $invoiceData = $crm->get('/invoices/' . $invoiceId);
        if ($invoiceData['status'] != 0) {
@@ -71,5 +71,7 @@
        } else {
            echo 'Invoice ' . $invoiceId . ': nothing to do' . "\n";
        }
        return $changed > 0;
    }
}
src/UcrmHelper.php
@@ -3,9 +3,9 @@
namespace SIPL\UCRM\Holidays;
class UcrmHelper {
    protected $rootDirectory;
    protected $api = NULL;
    protected $config = NULL;
    protected string $rootDirectory;
    protected ?\Ubnt\UcrmPluginSdk\Service\UcrmApi $api = NULL;
    protected ?array $config = NULL;
    protected $event = NULL;
    function __construct(?string $rootDirectory = NULL) {
@@ -15,18 +15,18 @@
        $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 getConfig() {
    function getConfig(): array {
        if ($this->config === NULL) {
            $configManager = \Ubnt\UcrmPluginSdk\Service\PluginConfigManager::create($this->rootDirectory);
            $this->config = $configManager->loadConfig();
@@ -34,7 +34,7 @@
        return $this->config;
    }
    function getCurrentEvent() {
    function getCurrentEvent(): array {
        if ($this->event === NULL) {
            try {
                if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
@@ -58,7 +58,7 @@
                    throw new \RuntimeException('Failed to process event - event not found');
                }
                if (!is_int($event['entityId'])) {
                if (!ctype_digit($event['entityId'])) {
                    throw new \RuntimeException('Failed to process event - invalid entity ID');
                }