Passed
Push — master ( 62efdc...fcc9e6 )
by
unknown
01:01 queued 12s
created

StreamTarget::update()   C

Complexity

Conditions 9
Paths 256

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
rs 6.5222
cc 9
nc 256
nop 8

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
// This code and all components (c) Copyright 2006 - 2018, Wowza Media Systems, LLC. All rights reserved.
4
// This code is licensed pursuant to the Wowza Public License version 1.0, available at www.wowza.com/legal.
5
//
6
7
namespace Com\Wowza;
8
9
use Com\Wowza\Entities\Application\Helpers\Settings;
10
11
class StreamTarget extends Wowza
12
{
13
    protected $sourceStreamName = 'myStream';
14
    protected $entryName = 'ppsource';
15
    protected $profile = 'rtmp';
16
    protected $host = 'localhost';
17
    protected $application = 'live';
18
    protected $userName = null;
19
    protected $password = null;
20
    protected $streamName = 'myStream';
21
    protected $appName;
22
    protected $port = 1935
23
24
    public function __construct(Settings $settings, $appName)
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_PUBLIC, expecting ',' or ';' on line 24 at column 4
Loading history...
25
    {
26
        parent::__construct($settings);
27
        $this->appName = $appName;
28
    }
29
30
    public function create(
31
        $sourceStreamName = null,
32
        $entryName = null,
33
        $profile = null,
34
        $host = null,
35
        $userName = null,
36
        $password = null,
37
        $streamName = null,
38
        $application = null,
39
        $port = null
40
    ) {
41
        $this->restURI = $this->getRestURI() . '/' . $entryName;
42
        $this->sourceStreamName = (!is_null($sourceStreamName)) ? $sourceStreamName : $this->sourceStreamName;
43
        $this->entryName = (!is_null($entryName)) ? $entryName : $this->entryName;
44
        $this->profile = (!is_null($profile)) ? $profile : $this->profile;
45
        $this->host = (!is_null($host)) ? $host : $this->host;
46
        $this->userName = (!is_null($userName)) ? $userName : $this->userName;
47
        $this->password = (!is_null($password)) ? $password : $this->password;
48
        $this->streamName = (!is_null($streamName)) ? $streamName : $this->streamName;
49
        $this->application = (!is_null($application)) ? $application : $this->application;
50
        $this->port = (!is_null($port)) ? ($int)$port : $this->port;
51
52
        $response = $this->sendRequest($this->preparePropertiesForRequest(self::class), []);
53
54
        return $response;
55
    }
56
57
    public function update(
58
        $sourceStreamName = null,
59
        $entryName = null,
60
        $profile = null,
61
        $host = null,
62
        $userName = null,
63
        $password = null,
64
        $streamName = null,
65
        $application = null,
66
        $port = null
67
    ) {
68
        $this->restURI = $this->getRestURI() . "/" . $entryName;
69
        $this->sourceStreamName = (!is_null($sourceStreamName)) ? $sourceStreamName : $this->sourceStreamName;
70
        $this->entryName = (!is_null($entryName)) ? $entryName : $this->entryName;
71
        $this->profile = (!is_null($profile)) ? $profile : $this->profile;
72
        $this->host = (!is_null($host)) ? $host : $this->host;
73
        $this->userName = (!is_null($userName)) ? $userName : $this->userName;
74
        $this->password = (!is_null($password)) ? $password : $this->password;
75
        $this->streamName = (!is_null($streamName)) ? $streamName : $this->streamName;
76
        $this->application = (!is_null($application)) ? $application : $this->application;
77
        $this->port = (!is_null($port)) ? ($int)$port : $this->port;
78
79
        return $this->sendRequest($this->preparePropertiesForRequest(self::class), [], self::VERB_PUT);
80
    }
81
82
    public function getAll()
83
    {
84
        $this->setNoParams();
85
        $this->restURI = $this->getRestURI();
86
87
        return $this->sendRequest($this->preparePropertiesForRequest(self::class), [], self::VERB_GET);
88
    }
89
90
    private function setNoParams()
91
    {
92
        $this->addSkipParameter('userName', true)//todo: correct key name?
93
        ->addSkipParameter('password', true)
94
            ->addSkipParameter('group', true)
95
            ->addSkipParameter('sourceStreamName', true)
96
            ->addSkipParameter('entryName', true)
97
            ->addSkipParameter('profile', true)
98
            ->addSkipParameter('host', true)
99
            ->addSkipParameter('application', true)
100
            ->addSkipParameter('streamName', true);
101
    }
102
103
    public function remove($entryName)
104
    {
105
        $this->setNoParams();
106
        $this->restURI = $this->getRestURI() . '/' . $entryName;
107
108
        return $this->sendRequest($this->preparePropertiesForRequest(self::class), [], self::VERB_DELETE);
109
    }
110
111
    protected function getRestURI()
112
    {
113
        return $this->getHost() . '/servers/' . $this->getServerInstance() . '/vhosts/' . $this->getVHostInstance() . '/applications/' . $this->appName . '/pushpublish/mapentries';
114
    }
115
}
116