Completed
Push — master ( ac5522...7a2611 )
by Vítězslav
05:36
created

FlexiBeeRO::performAction()   C

Complexity

Conditions 7
Paths 14

Size

Total Lines 37
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 26
nc 14
nop 2
dl 0
loc 37
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * FlexiPeeHP - Read Only Access to FlexiBee class.
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (C) 2015,2016 Spoje.Net
7
 */
8
9
namespace FlexiPeeHP;
10
11
class FlexiBeeRO extends \Ease\Brick
12
{
13
    /**
14
     * Základní namespace pro komunikaci s FlexiBee.
15
     * Basic namespace for communication with FlexiBee
16
     *
17
     * @var string Jmený prostor datového bloku odpovědi
18
     */
19
    public $nameSpace = 'winstrom';
20
21
    /**
22
     * Datový blok v poli odpovědi.
23
     * Data block in response field.
24
     *
25
     * @var string
26
     */
27
    public $resultField = 'results';
28
29
    /**
30
     * Verze protokolu použitého pro komunikaci.
31
     * Communication protocol version used.
32
     *
33
     * @var string Verze použitého API
34
     */
35
    public $protoVersion = '1.0';
36
37
    /**
38
     * Evidence užitá objektem.
39
     * Evidence used by object
40
     *
41
     * @link https://demo.flexibee.eu/c/demo/evidence-list Přehled evidencí
42
     * @var string
43
     */
44
    public $evidence = null;
45
46
    /**
47
     * Výchozí formát pro komunikaci.
48
     * Default communication format.
49
     *
50
     * @link https://www.flexibee.eu/api/dokumentace/ref/format-types Přehled možných formátů
51
     *
52
     * @var string json|xml|...
53
     */
54
    public $format = 'json';
55
56
    /**
57
     * Curl Handle.
58
     *
59
     * @var resource
60
     */
61
    public $curl = null;
62
63
    /**
64
     * @link https://demo.flexibee.eu/devdoc/company-identifier Identifikátor firmy
65
     * @var string
66
     */
67
    public $company = null;
68
69
    /**
70
     * Server[:port]
71
     * @var string
72
     */
73
    public $url = null;
74
75
    /**
76
     * REST API Username
77
     * @var string
78
     */
79
    public $user = null;
80
81
    /**
82
     * REST API Password
83
     * @var string
84
     */
85
    public $password = null;
86
87
    /**
88
     * @var array Pole HTTP hlaviček odesílaných s každým požadavkem
89
     */
90
    public $defaultHttpHeaders = ['User-Agent' => 'FlexiPeeHP v1.5'];
91
92
    /**
93
     * Default additional request url parameters after question mark
94
     * 
95
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls   Common params
96
     * @link https://www.flexibee.eu/api/dokumentace/ref/paging Paging params
97
     * @var array
98
     */
99
    public $defaultUrlParams = ['limit' => 0];
100
101
    /**
102
     * Identifikační řetězec.
103
     *
104
     * @var string
105
     */
106
    public $init = null;
107
108
    /**
109
     * Sloupeček s názvem.
110
     *
111
     * @var string
112
     */
113
    public $nameColumn = 'nazev';
114
115
    /**
116
     * Sloupeček obsahující datum vložení záznamu do shopu.
117
     *
118
     * @var string
119
     */
120
    public $myCreateColumn = 'false';
121
122
    /**
123
     * Slopecek obsahujici datum poslení modifikace záznamu do shopu.
124
     *
125
     * @var string
126
     */
127
    public $myLastModifiedColumn = 'lastUpdate';
128
129
    /**
130
     * Klíčový idendifikátor záznamu.
131
     *
132
     * @var string
133
     */
134
    public $fbKeyColumn = 'id';
135
136
    /**
137
     * Informace o posledním HTTP requestu.
138
     *
139
     * @var *
140
     */
141
    public $info;
142
143
    /**
144
     * Informace o poslední HTTP chybě.
145
     *
146
     * @var string
147
     */
148
    public $lastCurlError = null;
149
150
    /**
151
     * Used codes storage.
152
     *
153
     * @var array
154
     */
155
    public $codes = null;
156
157
    /**
158
     * Last Inserted ID.
159
     *
160
     * @var int
161
     */
162
    public $lastInsertedID = null;
163
164
    /**
165
     * Default Line Prefix.
166
     *
167
     * @var string
168
     */
169
    public $prefix = '/c/';
170
171
    /**
172
     * Raw Content of last curl response
173
     * 
174
     * @var string
175
     */
176
    public $lastCurlResponse;
177
178
    /**
179
     * HTTP Response code of last request
180
     *
181
     * @var int
182
     */
183
    public $lastResponseCode = null;
184
185
    /**
186
     * Array of fields for next curl POST operation
187
     *
188
     * @var array
189
     */
190
    protected $postFields = [];
191
192
    /**
193
     * Last operation result data or message(s)
194
     *
195
     * @var array
196
     */
197
    public $lastResult = null;
198
199
    /**
200
     * Nuber from  @rowCount
201
     * @var int
202
     */
203
    public $rowCount = null;
204
205
    /**
206
     * @link https://demo.flexibee.eu/devdoc/actions Provádění akcí
207
     * @var string
208
     */
209
    protected $action;
210
211
    /**
212
     * Pole akcí které podporuje ta která evidence
213
     * @link https://demo.flexibee.eu/c/demo/faktura-vydana/actions.json Např. Akce faktury
214
     * @var array
215
     */
216
    public $actionsAvailable = null;
217
218
    /**
219
     * Parmetry pro URL
220
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Všechny podporované parametry
221
     * @var array
222
     */
223
    public $urlParams = [
224
        'dry-run',
225
        'fail-on-warning',
226
        'report-name',
227
        'report-lang',
228
        'report-sign',
229
        'detail',
230
        'mode',
231
        'limit',
232
        'start',
233
        'order',
234
        'sort',
235
        'add-row-count',
236
        'relations',
237
        'includes',
238
        'use-ext-id',
239
        'use-internal-id',
240
        'stitky-as-ids',
241
        'only-ext-ids',
242
        'no-ext-ids',
243
        'no-ids',
244
        'code-as-id',
245
        'no-http-errors',
246
        'export-settings',
247
        'as-gui',
248
        'code-in-response',
249
        'add-global-version',
250
        'encoding',
251
        'delimeter',
252
        'format',
253
        'auth',
254
        'skupina-stitku',
255
        'dir',
256
        'xpath', // See: https://www.flexibee.eu/api/dokumentace/ref/xpath/
257
        'dry-run', // See: https://www.flexibee.eu/api/dokumentace/ref/dry-run/
258
        'inDesktopApp' // Note: Undocumented function (html only)
259
    ];
260
261
    /**
262
     * Class for read only interaction with FlexiBee.
263
     *
264
     * @param mixed $init default record id or initial data
265
     * @param array $options Connection settings override
266
     */
267
    public function __construct($init = null, $options = [])
268
    {
269
        $this->init = $init;
270
271
        parent::__construct();
272
        $this->setUp($options);
273
        $this->curlInit();
274
        if (!is_null($init)) {
275
            $this->processInit($init);
276
        }
277
    }
278
279
    /**
280
     * SetUp Object to be ready for connect
281
     *
282
     * @param array $options Object Options
283
     */
284
    public function setUp($options = [])
285
    {
286 View Code Duplication
        if (isset($options['company'])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
            $this->company = $options['company'];
288
        } else {
289
            if (is_null($this->company) && defined('FLEXIBEE_COMPANY')) {
290
                $this->company = constant('FLEXIBEE_COMPANY');
291
            }
292
        }
293 View Code Duplication
        if (isset($options['url'])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
294
            $this->url = $options['url'];
295
        } else {
296
            if (is_null($this->url) && defined('FLEXIBEE_URL')) {
297
                $this->url = constant('FLEXIBEE_URL');
298
            }
299
        }
300 View Code Duplication
        if (isset($options['user'])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
301
            $this->user = $options['user'];
302
        } else {
303
            if (is_null($this->user) && defined('FLEXIBEE_LOGIN')) {
304
                $this->user = constant('FLEXIBEE_LOGIN');
305
            }
306
        }
307 View Code Duplication
        if (isset($options['password'])) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
308
            $this->password = $options['password'];
309
        } else {
310
            if (is_null($this->password) && defined('FLEXIBEE_PASSWORD')) {
311
                $this->password = constant('FLEXIBEE_PASSWORD');
312
            }
313
        }
314
        if (isset($options['evidence'])) {
315
            $this->setEvidence($options['evidence']);
316
        }
317
    }
318
319
    /**
320
     * Inicializace CURL
321
     */
322
    public function curlInit()
323
    {
324
        $this->curl = \curl_init(); // create curl resource
325
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); // return content as a string from curl_exec
326
        curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, true); // follow redirects (compatibility for future changes in FlexiBee)
327
        curl_setopt($this->curl, CURLOPT_HTTPAUTH, true);       // HTTP authentication
328
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); // FlexiBee by default uses Self-Signed certificates
329
        curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
330
        curl_setopt($this->curl, CURLOPT_VERBOSE, true); // For debugging
331
        curl_setopt($this->curl, CURLOPT_USERPWD,
332
            $this->user.':'.$this->password); // set username and password
333
    }
334
335
    /**
336
     * Zinicializuje objekt dle daných dat
337
     * 
338
     * @param mixed $init
339
     */
340
    public function processInit($init)
341
    {
342
        if (is_integer($init)) {
343
            $this->loadFromFlexiBee($init);
344
        } elseif (is_array($init)) {
345
            $this->takeData($init);
346
        } elseif (strstr($init, 'code:')) {
347
            $this->loadFromFlexiBee($init);
348
        }
349
    }
350
351
    /**
352
     * Nastaví Evidenci pro Komunikaci.
353
     * Set evidence for communication
354
     *
355
     * @param string $evidence evidence pathName to use
356
     */
357
    public function setEvidence($evidence)
358
    {
359
        $result = null;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
360
        if (array_key_exists($evidence, Structure::$evidence)) {
361
            $this->evidence = $evidence;
362
            $result         = true;
363
        } else {
364
            throw new Exception(sprintf('Try to set unsupported evidence %s',
365
                $evidence));
366
        }
367
        return $result;
368
    }
369
370
    /**
371
     * Vrací právě používanou evidenci pro komunikaci
372
     *
373
     * @return string
374
     */
375
    public function getEvidence()
376
    {
377
        return $this->evidence;
378
    }
379
380
    /**
381
     * Set used company.
382
     * Nastaví Firmu.
383
     *
384
     * @param string $company
385
     */
386
    public function setCompany($company)
387
    {
388
        $this->company = $company;
389
    }
390
391
    /**
392
     * Obtain company now used
393
     * Vrací právě používanou firmu
394
     *
395
     * @return string
396
     */
397
    public function getCompany()
398
    {
399
        return $this->company;
400
    }
401
402
    /**
403
     * Vrací název evidence použité v odpovědích z FlexiBee
404
     *
405
     * @return string
406
     */
407
    public function getResponseEvidence()
408
    {
409
        switch ($this->evidence) {
410
            case 'c':
411
                $evidence = 'companies';
412
                break;
413
            default:
414
                $evidence = $this->getEvidence();
415
                break;
416
        }
417
        return $evidence;
418
    }
419
420
    /**
421
     * Převede rekurzivně Objekt na pole.
422
     *
423
     * @param object|array $object
424
     *
425
     * @return array
426
     */
427
    public static function object2array($object)
428
    {
429
        $result = null;
430
        if (is_object($object)) {
431
            $objectData = get_object_vars($object);
432
            if (is_array($objectData) && count($objectData)) {
433
                $result = array_map('self::object2array', $objectData);
434
            }
435 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
436
            if (is_array($object)) {
437
                foreach ($object as $item => $value) {
438
                    $result[$item] = self::object2array($value);
439
                }
440
            } else {
441
                $result = $object;
442
            }
443
        }
444
445
        return $result;
446
    }
447
448
    /**
449
     * Převede rekurzivně v poli všechny objekty na jejich identifikátory.
450
     *
451
     * @param object|array $object
452
     *
453
     * @return array
454
     */
455
    public static function objectToID($object)
456
    {
457
        $result = null;
458
        if (is_object($object)) {
459
            $result = $object->__toString();
460 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
461
            if (is_array($object)) {
462
                foreach ($object as $item => $value) {
463
                    $result[$item] = self::objectToID($value);
464
                }
465
            } else { //String
466
                $result = $object;
467
            }
468
        }
469
470
        return $result;
471
    }
472
473
    /**
474
     * Return basic URL for used Evidence
475
     *
476
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Sestavování URL
477
     * @param string $urlSuffix
478
     */
479
    public function getEvidenceURL($urlSuffix = null)
480
    {
481
        if (is_null($urlSuffix)) {
482
            $urlSuffix = $this->getEvidence();
483
        } elseif ($urlSuffix[0] == ';') {
484
            $urlSuffix = $this->getEvidence().$urlSuffix;
485
        }
486
        return $this->url.$this->prefix.$this->company.'/'.$urlSuffix;
487
    }
488
489
    /**
490
     * Funkce, která provede I/O operaci a vyhodnotí výsledek.
491
     *
492
     * @param string $urlSuffix část URL za identifikátorem firmy.
493
     * @param string $method    HTTP/REST metoda
494
     * @param string $format    Requested format
495
     * @return array|boolean Výsledek operace
496
     */
497
    public function performRequest($urlSuffix = null, $method = 'GET',
498
                                   $format = null)
499
    {
500
        $this->rowCount = null;
501
        $url            = $this->getEvidenceURL($urlSuffix);
502
503
        $responseCode = $this->doCurlRequest($url, $method, $format);
0 ignored issues
show
Documentation introduced by
$method is of type string, but the function expects a object<FlexiPeeHP\strinf>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
504
505
        if (is_null($format)) {
506
            $format = $this->format;
507
        }
508
509
        switch ($responseCode) {
510
            case 200:
511
            case 201:
512
                // Parse response
513
                $responseDecoded = [];
514
515
                switch ($format) {
516
                    case 'json':
517
                        $responseDecoded = json_decode($this->lastCurlResponse,
518
                            true, 10);
519
                        if (($method == 'PUT') && isset($responseDecoded[$this->nameSpace][$this->resultField][0]['id'])) {
520
                            $this->lastInsertedID = $responseDecoded[$this->nameSpace][$this->resultField][0]['id'];
521
                            $this->setMyKey($this->lastInsertedID);
522
                        } else {
523
                            $this->lastInsertedID = null;
524
                            if (isset($responseDecoded[$this->nameSpace]['@rowCount'])) {
525
                                $this->rowCount = (int) $responseDecoded[$this->nameSpace]['@rowCount'];
526
                            }
527
                        }
528
                        $decodeError = json_last_error_msg();
529
                        if ($decodeError != 'No error') {
530
                            $this->addStatusMessage($decodeError, 'error');
531
                        }
532
                        break;
533
                    case 'xml':
534
                        if (strlen($this->lastCurlResponse)) {
535
                            $responseDecoded = self::xml2array($this->lastCurlResponse);
536
                        } else {
537
                            $responseDecoded = null;
538
                        }
539
                        break;
540
                }
541
542
543
                $response         = $this->lastResult = $this->unifyResponseFormat($responseDecoded);
544
545
                break;
546
547
            default: //Some goes wrong
548
                $this->lastCurlError = curl_error($this->curl);
549
                switch ($format) {
550
                    case 'json':
551
                        $response = preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/',
552
                            function ($match) {
553
                            return mb_convert_encoding(pack('H*', $match[1]),
554
                                'UTF-8', 'UCS-2BE');
555
                        }, $this->lastCurlResponse);
556
                        $response = (json_encode(json_decode($response, true, 10),
557
                                JSON_PRETTY_PRINT));
558
                        break;
559
                    case 'xml':
560
                        if (strlen($this->lastCurlResponse)) {
561
                            $response = self::xml2array($this->lastCurlResponse);
562
                        }
563
                        break;
564
                }
565
566
                if (is_array($response)) {
567
                    $result = urldecode(http_build_query($response));
0 ignored issues
show
Bug introduced by
The variable $response does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
568
                } elseif (strlen($response) && ($response != 'null')) {
569
                    $result = urldecode(http_build_query(self::object2array(current(json_decode($response)))));
570
                } else {
571
                    $result = null;
572
                }
573
574
                if ($response == 'null') {
575
                    if ($this->lastResponseCode == 200) {
576
                        $response = true;
577
                    } else {
578
                        $response = null;
579
                    }
580
                } else {
581
                    if (is_string($response)) {
582
                        $response = self::object2array(current(json_decode($response)));
583
                    }
584
                }
585
586
                if (is_array($response) && ($this->lastResponseCode == 400)) {
587
                    $this->logResult($response, $url);
588
                } else {
589
                    $this->addStatusMessage(sprintf('Error (HTTP %d): <pre>%s</pre> %s',
590
                            curl_getinfo($this->curl, CURLINFO_HTTP_CODE),
591
                            $result, $this->lastCurlError), 'error');
592
                    $this->addStatusMessage($url, 'info');
593
                    if (count($this->postFields)) {
594
                        if (is_array($result)) {
595
                            $this->addStatusMessage(urldecode(http_build_query($this->postFields)),
596
                                'debug');
597
                        } else {
598
                            $this->addStatusMessage(urldecode(http_build_query($this->getData())),
599
                                'debug');
600
                        }
601
                    }
602
                }
603
604
                break;
605
        }
606
        return $response;
607
    }
608
609
    /**
610
     * Vykonej HTTP požadavek
611
     *
612
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Sestavování URL
613
     * @param string $url    URL požadavku
614
     * @param strinf $method HTTP Method GET|POST|PUT|OPTIONS|DELETE
615
     * @param string $format požadovaný formát komunikace
616
     * @return int HTTP Response CODE
617
     */
618
    public function doCurlRequest($url, $method, $format = null)
619
    {
620
        if (is_null($format)) {
621
            $format = $this->format;
622
        }
623
        curl_setopt($this->curl, CURLOPT_URL, $url);
624
// Nastavení samotné operace
625
        curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));
626
//Vždy nastavíme byť i prázná postdata jako ochranu před chybou 411
627
        curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->postFields);
628
629
        $httpHeaders = $this->defaultHttpHeaders;
630
        switch ($format) {
631
            case 'json':
632
                $httpHeaders['Accept']       = 'application/json';
633
                $httpHeaders['Content-Type'] = 'application/json';
634
635
                break;
636
            case 'xml':
637
                $httpHeaders['Accept']       = 'application/xml';
638
                $httpHeaders['Content-Type'] = 'application/xml';
639
                break;
640
        }
641
642
        $httpHeadersFinal = [];
643
        foreach ($httpHeaders as $key => $value) {
644
            $httpHeadersFinal[] = $key.': '.$value;
645
        }
646
647
        curl_setopt($this->curl, CURLOPT_HTTPHEADER, $httpHeadersFinal);
648
649
// Proveď samotnou operaci
650
        $this->lastCurlResponse = curl_exec($this->curl);
651
652
        $this->info = curl_getinfo($this->curl);
653
654
        $this->lastResponseCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
655
        return $this->lastResponseCode;
656
    }
657
658
    /**
659
     * Nastaví druh prováděné akce.
660
     *
661
     * @link https://demo.flexibee.eu/devdoc/actions Provádění akcí
662
     * @param string $action
663
     * @return boolean
664
     */
665
    public function setAction($action)
666
    {
667
        $result = false;
668
        if (is_null($this->actionsAvailable)) {
669
            $this->action = $action;
670
            $result       = true;
671
        } else {
672
            if (array_search($action, $this->actionsAvailable)) {
673
                $this->action = $action;
674
                $result       = true;
675
            }
676
        }
677
        return $result;
678
    }
679
680
    /**
681
     * Convert XML to array.
682
     *
683
     * @param string $xml
684
     *
685
     * @return array
686
     */
687
    public static function xml2array($xml)
688
    {
689
        $arr = [];
690
691
        if (is_string($xml)) {
692
            $xml = simplexml_load_string($xml);
693
        }
694
695
        foreach ($xml->children() as $r) {
696
            if (count($r->children()) == 0) {
697
                $arr[$r->getName()] = strval($r);
698
            } else {
699
                $arr[$r->getName()][] = self::xml2array($r);
700
            }
701
        }
702
703
        return $arr;
704
    }
705
706
    /**
707
     * Odpojení od FlexiBee.
708
     */
709
    public function disconnect()
710
    {
711
        if (is_resource($this->curl)) {
712
            curl_close($this->curl);
713
        }
714
        $this->curl = null;
715
    }
716
717
    public function __destruct()
718
    {
719
        $this->disconnect();
720
    }
721
722
    /**
723
     * Načte řádek dat z FlexiBee.
724
     *
725
     * @param int $recordID id požadovaného záznamu
726
     *
727
     * @return array
728
     */
729
    public function getFlexiRow($recordID)
730
    {
731
        $record   = null;
732
        $response = $this->performRequest($this->evidence.'/'.$recordID.'.json');
733
        if (isset($response[$this->evidence])) {
734
            $record = $response[$this->evidence][0];
735
        }
736
737
        return $record;
738
    }
739
740
    /**
741
     * Oddělí z pole podmínek ty jenž patří za ? v URL požadavku
742
     *
743
     * @link https://www.flexibee.eu/api/dokumentace/ref/urls/ Sestavování URL
744
     * @param array $conditions pole podmínek   - rendrují se do ()
745
     * @param array $urlParams  pole parametrů  - rendrují za ?
746
     */
747
    public function extractUrlParams(&$conditions, &$urlParams)
748
    {
749
        foreach ($this->urlParams as $urlParam) {
750
            if (isset($conditions[$urlParam])) {
751
                \Ease\Sand::divDataArray($conditions, $urlParams, $urlParam);
752
            }
753
        }
754
    }
755
756
    /**
757
     * Načte data z FlexiBee.
758
     *
759
     * @param string $suffix     dotaz
760
     * @param string|array $conditions Volitelný filtrovací výraz
761
     */
762
    public function getFlexiData($suffix = null, $conditions = null)
763
    {
764
        $urlParams = $this->defaultUrlParams;
765
        if (!is_null($conditions)) {
766
            if (is_array($conditions)) {
767
                $this->extractUrlParams($conditions, $urlParams);
768
                $conditions = $this->flexiUrl($conditions);
769
            }
770
771
            if (strlen($conditions) && ($conditions[0] != '/')) {
772
                $conditions = '/'.rawurlencode('('.($conditions).')');
773
            }
774
        } else {
775
            $conditions = '';
776
        }
777
        if (strlen($suffix)) {
778
            $transactions = $this->performRequest($this->evidence.$conditions.'.'.$this->format.'?'.$suffix.'&'.http_build_query($urlParams),
779
                'GET');
780
        } else {
781
            $transactions = $this->performRequest($this->evidence.$conditions.'.'.$this->format.'?'.http_build_query($urlParams),
782
                'GET');
783
        }
784
        if (isset($transactions[$this->evidence])) {
785
            $result = $transactions[$this->evidence];
786
        } else {
787
            $result = $transactions;
788
        }
789
790
        return $result;
791
    }
792
793
    /**
794
     * Načte záznam z FlexiBee.
795
     *
796
     * @param int $id ID záznamu
797
     *
798
     * @return int počet načtených položek
799
     */
800 View Code Duplication
    public function loadFromFlexiBee($id = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
801
    {
802
        $data = [];
803
        if (is_null($id)) {
804
            $id = $this->getMyKey();
805
        }
806
807
        $flexidata = $this->getFlexiData(null, '/'.$id);
808
        if (count($flexidata) == 1) {
809
            $data = current($flexidata);
810
        }
811
        return $this->takeData($data);
812
    }
813
814
    /**
815
     * Převede data do Json formátu pro FlexiBee.
816
     *
817
     * @param array $data
818
     *
819
     * @return string
820
     */
821
    public function jsonizeData($data)
822
    {
823
        $jsonize = [
824
            $this->nameSpace => [
825
                '@version' => $this->protoVersion,
826
                $this->evidence => $this->objectToID($data),
827
            ],
828
        ];
829
830
        if (!is_null($this->action)) {
831
            $jsonize[$this->nameSpace][$this->evidence.'@action'] = $this->action;
832
            $this->action                                         = null;
833
        }
834
835
        return json_encode($jsonize);
836
    }
837
838
    /**
839
     * Test if given record ID exists in FlexiBee.
840
     *
841
     * @param string|int $identifer
842
     */
843
    public function idExists($identifer = null)
844
    {
845
        if (is_null($identifer)) {
846
            $identifer = $this->getMyKey();
847
        }
848
        $flexiData = $this->getFlexiData(
849
            'detail=custom:'.$this->getmyKeyColumn(), $identifer);
850
851
        return $flexiData;
852
    }
853
854
    /**
855
     * Test if given record exists in FlexiBee.
856
     *
857
     * @param array $data
858
     * @return boolean Record presence status
859
     */
860
    public function recordExists($data = null)
861
    {
862
        $found = null;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
863
        if (is_null($data)) {
864
            $data = $this->getData();
865
        }
866
867
        $res = $this->getColumnsFromFlexibee([$this->myKeyColumn],
868
            self::flexiUrl($data));
0 ignored issues
show
Documentation introduced by
self::flexiUrl($data) is of type string, but the function expects a array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
869
870
        if (!count($res) || (isset($res['success']) && ($res['success'] == 'false'))
871
            || !count($res[0])) {
872
            $found = false;
873
        } else {
874
            $found = true;
875
        }
876
        return $found;
877
    }
878
879
    /**
880
     * Vrací z FlexiBee sloupečky podle podmínek.
881
     *
882
     * @param array|int|string $conditions pole podmínek nebo ID záznamu
883
     * @param string           $indexBy    klice vysledku naplnit hodnotou ze
884
     *                                     sloupečku
885
     * @return array
886
     */
887 View Code Duplication
    public function getAllFromFlexibee($conditions = null, $indexBy = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
888
    {
889
        if (is_int($conditions)) {
890
            $conditions = [$this->getmyKeyColumn() => $conditions];
891
        }
892
893
        $flexiData = $this->getFlexiData('', $conditions);
894
895
        if (!is_null($indexBy)) {
896
            $flexiData = $this->reindexArrayBy($flexiData);
897
        }
898
899
        return $flexiData;
900
    }
901
902
    /**
903
     * Vrací z FlexiBee sloupečky podle podmínek.
904
     *
905
     * @param string[] $columnsList seznam položek
906
     * @param array    $conditions  pole podmínek nebo ID záznamu
907
     * @param string   $indexBy     Sloupeček podle kterého indexovat záznamy
908
     *
909
     * @return array
910
     */
911
    public function getColumnsFromFlexibee($columnsList, $conditions = null,
912
                                           $indexBy = null)
913
    {
914
        $detail = 'full';
915
916
        if (is_int($conditions)) {
917
            $conditions = [$this->getmyKeyColumn() => $conditions];
918
        }
919
920
        if ($columnsList != '*') {
921
            if (is_array($columnsList)) {
922
                $columns = implode(',', array_unique($columnsList));
923
            } else {
924
                $columns = $columnsList;
925
            }
926
            $detail = 'custom:'.$columns;
927
        }
928
929
        $flexiData = $this->getFlexiData('detail='.$detail, $conditions);
930
931
        if (!is_null($indexBy)) {
932
            $flexiData = $this->reindexArrayBy($flexiData, $indexBy);
933
        }
934
935
        return $flexiData;
936
    }
937
938
    /**
939
     * Vrací kód záznamu.
940
     *
941
     * @param mixed $data
942
     *
943
     * @return string
944
     */
945
    public function getKod($data = null, $unique = true)
946
    {
947
        $kod = null;
948
949
        if (is_null($data)) {
950
            $data = $this->getData();
951
        }
952
953
        if (is_string($data)) {
954
            $data = [$this->nameColumn => $data];
955
        }
956
957
        if (isset($data['kod'])) {
958
            $kod = $data['kod'];
959
        } else {
960
            if (isset($data[$this->nameColumn])) {
961
                $kod = preg_replace('/[^a-zA-Z0-9]/', '',
962
                    \Ease\Sand::rip($data[$this->nameColumn]));
963
            } else {
964
                if (isset($data[$this->myKeyColumn])) {
965
                    $kod = \Ease\Sand::rip($data[$this->myKeyColumn]);
966
                }
967
            }
968
        }
969
970
        if (!strlen($kod)) {
971
            $kod = 'NOTSET';
972
        }
973
974
        if (strlen($kod) > 18) {
975
            $kodfinal = strtoupper(substr($kod, 0, 18));
976
        } else {
977
            $kodfinal = strtoupper($kod);
978
        }
979
980
        if ($unique) {
981
            $counter = 0;
982
            if (count($this->codes)) {
983
                foreach ($this->codes as $codesearch => $keystring) {
984
                    if (strstr($codesearch, $kodfinal)) {
985
                        ++$counter;
986
                    }
987
                }
988
            }
989
            if ($counter) {
990
                $kodfinal = $kodfinal.$counter;
991
            }
992
993
            $this->codes[$kodfinal] = $kod;
994
        }
995
996
        return $kodfinal;
997
    }
998
999
    /**
1000
     * Write Operation Result.
1001
     *
1002
     * @param array  $resultData
1003
     * @param string $url        URL
1004
     * @return boolean Log save success
1005
     */
1006
    public function logResult($resultData = null, $url = null)
1007
    {
1008
        $logResult = false;
1009
        if (isset($resultData['success']) && ($resultData['success'] == 'false')) {
1010
            if (isset($resultData['message'])) {
1011
                $this->addStatusMessage($resultData['message'], 'warning');
1012
            }
1013
            $this->addStatusMessage('Error '.$this->lastResponseCode.': '.urldecode($url),
1014
                'warning');
1015
            unset($url);
1016
        }
1017
        if (is_null($resultData)) {
1018
            $resultData = $this->lastResult;
1019
        }
1020
        if (isset($url)) {
1021
            $this->logger->addStatusMessage(urldecode($url));
1022
        }
1023
1024
        if (isset($resultData['results'])) {
1025
            $status = null;
0 ignored issues
show
Unused Code introduced by
$status is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1026
            if ($resultData['success'] == 'false') {
1027
                $status = 'error';
1028
            } else {
1029
                $status = 'success';
1030
            }
1031
            foreach ($resultData['results'] as $result) {
1032
                if (isset($result['request-id'])) {
1033
                    $rid = $result['request-id'];
1034
                } else {
1035
                    $rid = '';
1036
                }
1037
                if (isset($result['errors'])) {
1038
                    foreach ($result['errors'] as $error) {
1039
                        $message = $error['message'];
1040
                        if (isset($error['for'])) {
1041
                            $message .= ' for: '.$error['for'];
1042
                        }
1043
                        if (isset($error['value'])) {
1044
                            $message .= ' value:'.$error['value'];
1045
                        }
1046
                        if (isset($error['code'])) {
1047
                            $message .= ' code:'.$error['code'];
1048
                        }
1049
                        $this->addStatusMessage($rid.': '.$message, $status);
1050
                    }
1051
                }
1052
            }
1053
        }
1054
1055
        if (is_object($this->logger)) {
1056
            $logResult = $this->logger->flush(get_class($this));
1057
        }
1058
        return $logResult;
1059
    }
1060
1061
    /**
1062
     * Save RAW Curl Request & Response to files in Temp directory
1063
     */
1064
    public function saveDebugFiles()
1065
    {
1066
        $tmpdir = sys_get_temp_dir();
1067
        file_put_contents($tmpdir.'/request-'.$this->evidence.'-'.microtime().'.'.$this->format,
1068
            $this->postFields);
1069
        file_put_contents($tmpdir.'/response-'.$this->evidence.'-'.microtime().'.'.$this->format,
1070
            $this->lastCurlResponse);
1071
    }
1072
1073
    /**
1074
     * Připraví data pro odeslání do FlexiBee
1075
     * 
1076
     * @param string $data
1077
     */
1078
    public function setPostFields($data)
1079
    {
1080
        $this->postFields = $data;
0 ignored issues
show
Documentation Bug introduced by
It seems like $data of type string is incompatible with the declared type array of property $postFields.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
1081
    }
1082
1083
    /**
1084
     * Generuje fragment url pro filtrování.
1085
     *
1086
     * @see https://www.flexibee.eu/api/dokumentace/ref/filters
1087
     *
1088
     * @param array  $data
1089
     * @param string $joiner default and/or
1090
     * @param string $defop  default operator
1091
     *
1092
     * @return string
1093
     */
1094
    public static function flexiUrl(array $data, $joiner = 'and', $defop = 'eq')
1095
    {
1096
        $flexiUrl = '';
0 ignored issues
show
Unused Code introduced by
$flexiUrl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1097
        $parts    = [];
1098
1099
        foreach ($data as $column => $value) {
1100
            if (is_integer($data[$column]) || is_float($data[$column])) {
1101
                $parts[$column] = $column.' eq \''.$data[$column].'\'';
1102
            } elseif (is_bool($data[$column])) {
1103
                $parts[$column] = $data[$column] ? $column.' eq true' : $column.' eq false';
1104
            } elseif (is_null($data[$column])) {
1105
                $parts[$column] = $column." is null";
1106
            } elseif ($value == '!null') {
1107
                $parts[$column] = $column." is not null";
1108
            } else {
1109
                $parts[$column] = $column." $defop '".$data[$column]."'";
1110
            }
1111
        }
1112
1113
        $flexiUrl = implode(' '.$joiner.' ', $parts);
1114
1115
        return $flexiUrl;
1116
    }
1117
1118
    /**
1119
     * Vrací identifikátor objektu code: nebo id:
1120
     *
1121
     * @link https://demo.flexibee.eu/devdoc/identifiers Identifikátory záznamů
1122
     * @return string indentifikátor záznamu reprezentovaného objektem
1123
     */
1124
    public function __toString()
1125
    {
1126
        $myCode = $this->getDataValue('kod');
1127
        if ($myCode) {
1128
            $id = 'code:'.$myCode;
1129
        } else {
1130
            $id = $this->getDataValue('id');
1131
            if (is_null($id)) {
1132
                $this->addToLog('Object Data does not contain code: or id: cannot match with statement!',
1133
                    'warning');
1134
            }
1135
        }
1136
        return $id;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $id; (object|integer|double|string|array|boolean|null) is incompatible with the return type of the parent method Ease\Sand::__toString of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
1137
    }
1138
1139
    /**
1140
     * Gives you FlexiPeeHP class name for Given Evidence
1141
     *
1142
     * @param string $evidence
1143
     * @return string Class name
1144
     */
1145
    static public function evidenceToClassName($evidence)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
1146
    {
1147
        return str_replace(' ', '', ucwords(str_replace('-', ' ', $evidence)));
1148
    }
1149
1150
    /**
1151
     * Vrací hodnotu daného externího ID
1152
     *
1153
     * @param string $want Which ? If empty,you obtain the first one.
1154
     * @return string
1155
     */
1156
    public function getExternalID($want = null)
1157
    {
1158
        $extid = null;
1159
        $ids   = $this->getDataValue('external-ids');
1160
        if (is_null($want)) {
1161
            if (count($ids)) {
1162
                $extid = current($ids);
1163
            }
1164
        } else {
1165
            if (!is_null($ids)) {
1166
                foreach ($ids as $id) {
0 ignored issues
show
Bug introduced by
The expression $ids of type object|integer|double|string|array|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
1167
                    if (strstr($id, 'ext:'.$want)) {
1168
                        $extid = str_replace('ext:'.$want.':', '', $id);
1169
                    }
1170
                }
1171
            }
1172
        }
1173
        return $extid;
1174
    }
1175
1176
    /**
1177
     * Obtain actual GlobalVersion
1178
     * Vrací aktuální globální verzi změn
1179
     *
1180
     * @link https://www.flexibee.eu/api/dokumentace/ref/changes-api#globalVersion Globální Verze
1181
     * @return type
1182
     */
1183
    public function getGlobalVersion()
1184
    {
1185
        $globalVersion = null;
1186
        if (!count($this->lastResult) || !isset($this->lastResult['@globalVersion'])) {
1187
            $this->getFlexiData(null,
1188
                ['add-global-version' => 'true', 'limit' => 1]);
1189
        }
1190
1191
        if (isset($this->lastResult['@globalVersion'])) {
1192
            $globalVersion = intval($this->lastResult['@globalVersion']);
1193
        }
1194
1195
        return $globalVersion;
1196
    }
1197
1198
    /**
1199
     * Return the same response format for one and multiplete results
1200
     * 
1201
     * @param array $responseRaw
1202
     * @return array
1203
     */
1204
    public function unifyResponseFormat($responseRaw)
1205
    {
1206
        $response = null;
1207
        $evidence = $this->getResponseEvidence();
1208
        if (is_array($responseRaw)) {
1209
            // Get response body root automatically
1210
            if (array_key_exists($this->nameSpace, $responseRaw)) { //Unifi response format
1211
                $responseBody = $responseRaw[$this->nameSpace];
1212
                if (array_key_exists($evidence, $responseBody)) {
1213
                    $evidenceContent = $responseBody[$evidence];
1214
                    if (array_key_exists(0, $evidenceContent)) {
1215
                        $response[$evidence] = $evidenceContent; //Multiplete Results
1216
                    } else {
1217
                        $response[$evidence][0] = $evidenceContent; //One result
1218
                    }
1219
                } else {
1220
                    $response = $responseBody;
1221
                }
1222
            } else {
1223
                $response = $responseRaw;
1224
            }
1225
        }
1226
        return $response;
1227
    }
1228
1229
    /**
1230
     * Obtain structure for given (or current) evidence
1231
     *
1232
     * @param string $evidence
1233
     * @return array Evidence structure
1234
     */
1235
    public function getColumnsInfo($evidence = null)
1236
    {
1237
        $columnsInfo = null;
1238
        if (is_null($evidence)) {
1239
            $evidence = $this->getEvidence();
1240
        }
1241
        $propsName = lcfirst(\FlexiPeeHP\FlexiBeeRO::evidenceToClassName($evidence));
1242
        if (isset(\FlexiPeeHP\Structure::$$propsName)) {
1243
            $columnsInfo = \FlexiPeeHP\Structure::$$propsName;
1244
        }
1245
        return $columnsInfo;
1246
    }
1247
1248
    /**
1249
     * Obtain actions for given (or current) evidence
1250
     *
1251
     * @param string $evidence
1252
     * @return array Evidence structure
1253
     */
1254
    public function getActionsInfo($evidence = null)
1255
    {
1256
        $actionsInfo = null;
1257
        if (is_null($evidence)) {
1258
            $evidence = $this->getEvidence();
1259
        }
1260
        $propsName = lcfirst(\FlexiPeeHP\FlexiBeeRO::evidenceToClassName($evidence));
1261
        if (isset(\FlexiPeeHP\Actions::$$propsName)) {
1262
            $actionsInfo = \FlexiPeeHP\Actions::$$propsName;
1263
        }
1264
        return $actionsInfo;
1265
    }
1266
1267
    /**
1268
     * Perform given action (if availble) on current evidence/record
1269
     * @url https://demo.flexibee.eu/devdoc/actions
1270
     * 
1271
     * @param string $action one of evidence actions
1272
     * @param string $method ext|int External method call operation in URL.
1273
     *                               Internal add the @action element to request body
1274
     */
1275
    public function performAction($action, $method = 'ext')
1276
    {
1277
        $result = null;
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1278
        if (is_null($this->actionsAvailable)) {
1279
            $this->actionsAvailble = $this->getActionsInfo();
0 ignored issues
show
Bug introduced by
The property actionsAvailble does not seem to exist. Did you mean action?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1280
        }
1281
1282
        if (is_array($this->actionsAvailble) && array_key_exists($action,
0 ignored issues
show
Bug introduced by
The property actionsAvailble does not seem to exist. Did you mean action?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1283
                $this->actionsAvailble)) {
0 ignored issues
show
Bug introduced by
The property actionsAvailble does not seem to exist. Did you mean action?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1284
            switch ($this->actionsAvailble[$action]['actionMakesSense']) {
0 ignored issues
show
Bug introduced by
The property actionsAvailble does not seem to exist. Did you mean action?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1285
                case 'ONLY_WITH_INSTANCE_AND_NOT_IN_EDIT':
1286
                case 'ONLY_WITH_INSTANCE': //Add instance
1287
                    $urlSuffix = '/'.$this->__toString().'/'.$action.'.'.$this->format;
1288
                    break;
1289
1290
                default:
1291
                    $urlSuffix = '/'.$action;
1292
                    break;
1293
            }
1294
1295
            switch ($method) {
1296
                case 'int':
1297
                    $this->setAction($action);
1298
                    $result       = $this->performRequest(null, 'POST');
1299
                    break;
1300
1301
                default:
1302
                    $result = $this->performRequest($urlSuffix, 'GET');
1303
                    break;
1304
            }
1305
        } else {
1306
            throw new Exception(sprintf(_('Unsupported action %s for evidence %s'),
1307
                $action, $this->getEvidence()));
1308
        }
1309
1310
        return $result;
1311
    }
1312
1313
}
1314