Completed
Push — master ( fffb97...85dbdb )
by Dmitry
03:32
created

Reports   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 118
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B get() 0 33 3
A setProcessingMode() 0 5 1
A setReturnMoneyInMicros() 0 8 4
A setSkipReportHeader() 0 5 1
A setSkipColumnHeader() 0 5 1
A setSkipReportSummary() 0 5 1
1
<?php
2
3
namespace Yandex\Direct\Service;
4
5
use Yandex\Direct\Service;
6
7
/**
8
 * Class Reports
9
 *
10
 * @author Dmitry Gladyshev <[email protected]>
11
 */
12
final class Reports extends Service
13
{
14
    /**
15
     * Спецификация отчета.
16
     *
17
     * @param $SelectionCriteria
18
     * @param $FieldNames
19
     * @param $ReportName
20
     * @param $ReportType
21
     * @param $DateRangeType
22
     * @param $Format
23
     * @param $IncludeVAT
24
     * @param $IncludeDiscount
25
     * @param $Page
26
     * @param $OrderBy
27
     * @return string
28
     * @see https://tech.yandex.ru/direct/doc/reports/spec-docpage/
29
     */
30
    public function get($SelectionCriteria, $FieldNames, $ReportName, $ReportType, $DateRangeType,
31
                        $Page = null, $OrderBy = null,
32
                        $IncludeVAT = 'YES', $IncludeDiscount = 'YES', $Format = 'TSV')
33
    {
34
        $params = [
35
            'SelectionCriteria' => $SelectionCriteria,
36
            'FieldNames' => $FieldNames,
37
            'Page' => $Page,
38
            'OrderBy' => $OrderBy,
39
            'ReportName' => $ReportName, 
40
            'ReportType' => $ReportType, 
41
            'DateRangeType' => $DateRangeType,
42
            'Format' => $Format,
43
            'IncludeVAT' => $IncludeVAT, 
44
            'IncludeDiscount' => $IncludeDiscount,
45
        ];
46
47
        if ($Page) {
48
            $params['Page'] = $Page;
49
        } else {
50
            unset($params['Page']);
51
        }
52
53
        if ($OrderBy) {
54
            $params['OrderBy'] = $OrderBy;
55
        } else {
56
            unset($params['OrderBy']);
57
        }
58
59
        return $this->request([
60
            'params' => $params
61
        ]);
62
    }
63
64
    /**
65
     * Режим формирования отчета: online, offline или auto.
66
     * Отсутствие заголовка эквивалентно значению auto.
67
     *
68
     * @param $processingMode
69
     * @return $this
70
     * @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
71
     */
72
    public function setProcessingMode($processingMode)
73
    {
74
        $this->headers['processingMode'] = $processingMode;
75
        return $this;
76
    }
77
78
    /**
79
     * Если заголовок указан, денежные значения в отчете возвращаются в валюте с точностью до двух знаков после
80
     * запятой. Если не указан, денежные значения возвращаются в виде целых чисел — сумм в валюте,
81
     * умноженных на 1 000 000.
82
     *
83
     * @param $returnMoneyInMicros
84
     * @return $this
85
     * @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
86
     */
87
    public function setReturnMoneyInMicros($returnMoneyInMicros)
88
    {
89
        if (is_numeric($returnMoneyInMicros) || is_bool($returnMoneyInMicros)) {
90
            $returnMoneyInMicros = $returnMoneyInMicros ? 'true' : 'false';
91
        }
92
        $this->headers['returnMoneyInMicros'] = $returnMoneyInMicros;
93
        return $this;
94
    }
95
96
    /**
97
     * Не выводить в отчете строку с названием отчета и диапазоном дат.
98
     * @return $this
99
     * @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
100
     */
101
    public function setSkipReportHeader()
102
    {
103
        $this->headers['skipReportHeader'] = 'true';
104
        return $this;
105
    }
106
107
    /**
108
     * Не выводить в отчете строку с названиями полей.
109
     *
110
     * @return $this
111
     * @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
112
     */
113
    public function setSkipColumnHeader()
114
    {
115
        $this->headers['skipColumnHeader'] = 'true';
116
        return $this;
117
    }
118
119
    /**
120
     * Не выводить в отчете строку с количеством строк статистики.
121
     *
122
     * @see https://tech.yandex.ru/direct/doc/reports/headers-docpage/
123
     */
124
    public function setSkipReportSummary()
125
    {
126
        $this->headers['skipReportSummary'] = 'true';
127
        return $this;
128
    }
129
}
130