Passed
Pull Request — master (#60)
by
unknown
03:17
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
23
    public function __construct(Settings $settings, $appName)
24
    {
25
        parent::__construct($settings);
26
        $this->appName = $appName;
27
    }
28
29
    public function create(
30
        $sourceStreamName = null,
31
        $entryName = null,
32
        $profile = null,
33
        $host = null,
34
        $userName = null,
35
        $password = null,
36
        $streamName = null,
37
        $application = null
38
    ) {
39
        $this->restURI = $this->getRestURI() . '/' . $entryName;
40
        $this->sourceStreamName = (!is_null($sourceStreamName)) ? $sourceStreamName : $this->sourceStreamName;
41
        $this->entryName = (!is_null($entryName)) ? $entryName : $this->entryName;
42
        $this->profile = (!is_null($profile)) ? $profile : $this->profile;
43
        $this->host = (!is_null($host)) ? $host : $this->host;
44
        $this->userName = (!is_null($userName)) ? $userName : $this->userName;
45
        $this->password = (!is_null($password)) ? $password : $this->password;
46
        $this->streamName = (!is_null($streamName)) ? $streamName : $this->streamName;
47
        $this->application = (!is_null($application)) ? $application : $this->application;
48
49
        $response = $this->sendRequest($this->preparePropertiesForRequest(self::class), []);
50
51
        return $response;
52
    }
53
54
    public function update(
55
        $sourceStreamName = null,
56
        $entryName = null,
57
        $profile = null,
58
        $host = null,
59
        $userName = null,
60
        $password = null,
61
        $streamName = null,
62
        $application = null
63
    ) {
64
        $this->restURI = $this->restURI . "/" . $entryName;
65
        $this->sourceStreamName = (!is_null($sourceStreamName)) ? $sourceStreamName : $this->sourceStreamName;
66
        $this->entryName = (!is_null($entryName)) ? $entryName : $this->entryName;
67
        $this->profile = (!is_null($profile)) ? $profile : $this->profile;
68
        $this->host = (!is_null($host)) ? $host : $this->host;
69
        $this->userName = (!is_null($userName)) ? $userName : $this->userName;
70
        $this->password = (!is_null($password)) ? $password : $this->password;
71
        $this->streamName = (!is_null($streamName)) ? $streamName : $this->streamName;
72
        $this->application = (!is_null($application)) ? $application : $this->application;
73
74
        return $this->sendRequest($this->preparePropertiesForRequest(self::class), [], self::VERB_PUT);
75
    }
76
77
    public function getAll()
78
    {
79
        $this->setNoParams();
80
        $this->restURI = $this->getRestURI();
81
82
        return $this->sendRequest($this->preparePropertiesForRequest(self::class), [], self::VERB_GET);
83
    }
84
85
    private function setNoParams()
86
    {
87
        $this->addSkipParameter('userName', true)//todo: correct key name?
88
        ->addSkipParameter('password', true)
89
            ->addSkipParameter('group', true)
90
            ->addSkipParameter('sourceStreamName', true)
91
            ->addSkipParameter('entryName', true)
92
            ->addSkipParameter('profile', true)
93
            ->addSkipParameter('host', true)
94
            ->addSkipParameter('application', true)
95
            ->addSkipParameter('streamName', true);
96
    }
97
98
    public function remove($entryName)
99
    {
100
        $this->setNoParams();
101
        $this->restURI = $this->getRestURI() . '/' . $entryName;
102
103
        return $this->sendRequest($this->preparePropertiesForRequest(self::class), [], self::VERB_DELETE);
104
    }
105
106
    protected function getRestURI()
107
    {
108
        return $this->getHost() . '/servers/' . $this->getServerInstance() . '/vhosts/' . $this->getVHostInstance() . '/applications/' . $this->appName . '/pushpublish/mapentries';
109
    }
110
}
111