Creatives::reportsGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 15
c 2
b 1
f 0
dl 0
loc 30
rs 9.7666
cc 1
nc 1
nop 12

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Promopult\TikTokMarketingApi\Service;
6
7
use Promopult\TikTokMarketingApi\AbstractService;
8
9
/**
10
 * @psalm-suppress UnusedClass
11
 */
12
final class Creatives extends AbstractService
13
{
14
    /**
15
     * Creative Asset Level reporting is essential to understand how an advertiser's creative assets resonated with
16
     * their target audience. This information can then be used to improve future creatives and refine audiences.
17
     * Developers can return performance metrics at the creative asset level as well as creative asset attributes like
18
     * height, width, and more.
19
     *
20
     * @param int $advertiserId         Advertiser ID
21
     * @param string $materialType      Material type. Optional value: VIDEO, IMAGE
22
     * @param array $infoFields         Use to specify whether to query all data
23
     * @param array $metricsFields      The metrics or dimension data that you need
24
     * @param string|null $startDate    Start time, closed interval. Format such as: 2020-01-01 (advertiser time zone)
25
     * @param string|null $endDate      End time, closed interval. Format such as: 2020-01-01 (advertiser time zone)
26
     * @param bool|null $lifetime       Use to specify whether to query all data. If so, you do not need to specify
27
     *                                  start_date and end_date.
28
     * @param array|null $filtering     Filtering criteria
29
     * @param string|null $orderField   Sort fields. Support sorting according to the creation time of the material
30
     *                                  and all the index data. Not sorted by default
31
     * @param string|null $orderType    Sort by. Optional values: ASC, DESC. Default: DESC
32
     * @param int|null $page            Current number of pages. Default value: 1, range: ≥ 1
33
     * @param int|null $pageSize        Page size. Default value: 10, range: 1-1000
34
     *
35
     * @return array
36
     *
37
     * @throws \Throwable
38
     *
39
     * @see https://ads.tiktok.com/marketing_api/docs?id=1701890967858177
40
     */
41
    public function reportsGet(
42
        int $advertiserId,
43
        string $materialType,
44
        array $infoFields,
45
        array $metricsFields,
46
        ?string $startDate,
47
        ?string $endDate,
48
        ?bool $lifetime = null,
49
        ?array $filtering = null,
50
        ?string $orderField = null,
51
        ?string $orderType = null,
52
        ?int $page = null,
53
        ?int $pageSize = null
54
    ): array {
55
        return $this->requestApi(
56
            'GET',
57
            '/open_api/v1.3/creative/report/get/',
58
            [
59
                'advertiser_id' => $advertiserId,
60
                'material_type' => $materialType,
61
                'info_fields' => $infoFields,
62
                'metrics_fields' => $metricsFields,
63
                'lifetime' => $lifetime,
64
                'start_date' => $startDate,
65
                'end_date' => $endDate,
66
                'filtering' => $filtering,
67
                'order_field' => $orderField,
68
                'order_type' => $orderType,
69
                'page' => $page,
70
                'page_size' => $pageSize,
71
            ]
72
        );
73
    }
74
}
75