Passed
Push — master ( c19d9e...2cc707 )
by Vítězslav
24:55
created

makeInvoice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 26
rs 9.568
cc 2
nc 2
nop 3
1
#!/usr/bin/php -f
2
<?php
3
/**
4
 * FlexiPeeHP - Example how to create Invoice
5
 *
6
 * @author     Vítězslav Dvořák <[email protected]>
7
 * @copyright  (G) 2018 Vitex Software
8
 */
9
10
namespace Example\FlexiPeeHP;
11
12
use \FlexiPeeHP\FlexiBeeRO;
13
use \FlexiPeeHP\FakturaVydana;
14
15
define('EASE_LOGGER', 'syslog|console');
16
include_once './config.php';
17
include_once '../vendor/autoload.php';
18
19
/**
20
 * Prepare Testing Invoice
21
 * 
22
 * @param array $initialData
23
 * 
24
 * @return FakturaVydana
25
 */
26
function makeInvoice($initialData = [], $dayBack = 1, $evidence = 'vydana')
27
{
28
    $yesterday = new \DateTime();
29
    $yesterday->modify('-'.$dayBack.' day');
30
    $testCode  = 'INV_'.\Ease\Sand::randomString();
0 ignored issues
show
Bug introduced by
The method randomString() does not exist on Ease\Sand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
    $testCode  = 'INV_'.\Ease\Sand::/** @scrutinizer ignore-call */ randomString();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
    $invoice   = new FakturaVydana(null, ['evidence' => 'faktura-'.$evidence]);
32
    $invoice->takeData(array_merge([
33
        'kod' => $testCode,
34
        'varSym' => \Ease\Sand::randomNumber(1111, 9999),
0 ignored issues
show
Bug introduced by
The method randomNumber() does not exist on Ease\Sand. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        'varSym' => \Ease\Sand::/** @scrutinizer ignore-call */ randomNumber(1111, 9999),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        'specSym' => \Ease\Sand::randomNumber(111, 999),
36
        'bezPolozek' => true,
37
        'popis' => 'php-flexibee-matcher Test invoice',
38
        'datVyst' => FlexiBeeRO::dateToFlexiDate($yesterday),
39
        'typDokl' => FlexiBeeRO::code('FAKTURA')
40
            ], $initialData));
41
    if ($invoice->sync()) {
42
        $invoice->addStatusMessage($invoice->getApiURL().' '.
43
            FlexiBeeRO::uncode($invoice->getDataValue('typDokl')).' '.
44
            FlexiBeeRO::uncode($invoice->getRecordIdent()).' '.
45
            FlexiBeeRO::uncode($invoice->getDataValue('sumCelkem')).' '.
46
            FlexiBeeRO::uncode($invoice->getDataValue('mena')), 'success');
47
    } else {
48
        $invoice->addStatusMessage(json_encode($invoice->getData()), 'debug');
49
    }
50
51
    return $invoice;
52
}
53
$invoice = makeInvoice(['id' => 'ext:example:1']);
54
55
56
//Set due date by DateTime object
57
$nextMonth = new \DateTime();
58
$nextMonth->modify('+1 month');
59
$invoice->setDataValue('datSplat', $nextMonth);
60
61
$invoice->addStatusMessage(_('Invoice').': '.$invoice->getRecordIdent().' '.$invoice->getRecordCode(),
62
    $invoice->sync() ? 'success' : 'error' );
63