Code Duplication    Length = 16-17 lines in 11 locations

lib/WebMarketingROI/OptimizelyPHP/Service/v2/Audiences.php 2 locations

@@ 92-108 (lines=17) @@
89
     * Create an Audience for a Project.
90
     * @param Result
91
     */
92
    public function create($audience)
93
    {
94
        if (!($audience instanceOf \WebMarketingROI\OptimizelyPHP\Resource\v2\Audience)) {
95
            throw new Exception("Expected argument of type Audience",
96
                    Exception::CODE_INVALID_ARG);
97
        }
98
        
99
        $postData = $audience->toArray();
100
        
101
        $result = $this->client->sendApiRequest("/audiences", array(), 'POST', 
102
                $postData, array(201));
103
        
104
        $audience = new Audience($result->getDecodedJsonData());
105
        $result->setPayload($audience);
106
        
107
        return $result;
108
    }
109
    
110
    /**
111
     * Update an Audience for a Project
@@ 116-132 (lines=17) @@
113
     * @param Result
114
     * @throws Exception
115
     */
116
    public function update($audienceId, $audience) 
117
    {
118
        if (!($audience instanceOf \WebMarketingROI\OptimizelyPHP\Resource\v2\Audience)) {
119
            throw new Exception("Expected argument of type Audience",
120
                    Exception::CODE_INVALID_ARG);
121
        }
122
        
123
        $postData = $audience->toArray();
124
                
125
        $result = $this->client->sendApiRequest("/audiences/$audienceId", array(), 'PATCH', 
126
                $postData, array(200));
127
        
128
        $audience = new Audience($result->getDecodedJsonData());
129
        $result->setPayload($audience);
130
        
131
        return $result;
132
    }
133
}
134
135

lib/WebMarketingROI/OptimizelyPHP/Service/v2/Campaigns.php 2 locations

@@ 133-149 (lines=17) @@
130
     * @return Result
131
     * @throws Exception
132
     */
133
    public function create($campaign)
134
    {
135
        if (!($campaign instanceOf Campaign)) {
136
            throw new Exception("Expected argument of type Campaign",
137
                    Exception::CODE_INVALID_ARG);
138
        }
139
        
140
        $postData = $campaign->toArray();
141
        
142
        $result = $this->client->sendApiRequest("/campaigns", array(), 'POST', 
143
                $postData);
144
        
145
        $campaign = new Campaign($result->getDecodedJsonData());
146
        $result->setPayload($campaign);
147
        
148
        return $result;
149
    }
150
    
151
    /**
152
     * Update a Campaign
@@ 158-174 (lines=17) @@
155
     * @return Result
156
     * @throws Exception
157
     */
158
    public function update($campaignId, $campaign) 
159
    {
160
        if (!($campaign instanceOf Campaign)) {
161
            throw new Exception("Expected argument of type Campaign",
162
                    Exception::CODE_INVALID_ARG);
163
        }
164
        
165
        $postData = $campaign->toArray();
166
                
167
        $result = $this->client->sendApiRequest("/campaigns/$campaignId", array(), 'PATCH', 
168
                $postData);
169
        
170
        $campaign = new Campaign($result->getDecodedJsonData());
171
        $result->setPayload($campaign);
172
        
173
        return $result;
174
    }
175
    
176
    /**
177
     * Delete Campaign by ID

lib/WebMarketingROI/OptimizelyPHP/Service/v2/Events.php 4 locations

@@ 99-115 (lines=17) @@
96
     * @return Result
97
     * @throws Exception
98
     */
99
    public function createClickEvent($pageId, $event)
100
    {
101
        if (!($event instanceOf ClickEvent)) {
102
            throw new Exception("Expected argument of type ClickEvent",
103
                    Exception::CODE_INVALID_ARG);
104
        }
105
        
106
        $postData = $event->toArray();
107
        
108
        $result = $this->client->sendApiRequest("/pages/$pageId/click_events", array(), 'POST', 
109
                $postData);
110
        
111
        $event = new ClickEvent($result->getDecodedJsonData());
112
        $result->setPayload($event);
113
        
114
        return $result;
115
    }
116
    
117
    /**
118
     * Creates a new custom event.
@@ 124-140 (lines=17) @@
121
     * @return Result
122
     * @throws Exception
123
     */
124
    public function createCustomEvent($pageId, $event)
125
    {
126
        if (!($event instanceOf CustomEvent)) {
127
            throw new Exception("Expected argument of type CustomEvent",
128
                    Exception::CODE_INVALID_ARG);
129
        }
130
        
131
        $postData = $event->toArray();
132
        
133
        $result = $this->client->sendApiRequest("/pages/$pageId/custom_events", array(), 'POST', 
134
                $postData);
135
        
136
        $event = new CustomEvent($result->getDecodedJsonData());
137
        $result->setPayload($event);
138
        
139
        return $result;
140
    }
141
        
142
    /**
143
     * Updates the given click event.
@@ 150-166 (lines=17) @@
147
     * @return Result
148
     * @throws Exception
149
     */
150
    public function updateClickEvent($pageId, $eventId, $event) 
151
    {
152
        if (!($event instanceOf ClickEvent)) {
153
            throw new Exception("Expected argument of type ClickEvent",
154
                    Exception::CODE_INVALID_ARG);
155
        }
156
        
157
        $postData = $event->toArray();
158
                
159
        $result = $this->client->sendApiRequest("/pages/$pageId/click_events/$eventId", array(), 'PATCH', 
160
                $postData);
161
        
162
        $event = new ClickEvent($result->getDecodedJsonData());
163
        $result->setPayload($event);
164
        
165
        return $result;
166
    }
167
    
168
    /**
169
     * Updates the given custom event.
@@ 176-192 (lines=17) @@
173
     * @return Result
174
     * @throws Exception
175
     */
176
    public function updateCustomEvent($pageId, $eventId, $event) 
177
    {
178
        if (!($event instanceOf CustomEvent)) {
179
            throw new Exception("Expected argument of type CustomEvent",
180
                    Exception::CODE_INVALID_ARG);
181
        }
182
        
183
        $postData = $event->toArray();
184
                
185
        $result = $this->client->sendApiRequest("/pages/$pageId/custom_events/$eventId", array(), 'PATCH', 
186
                $postData);        
187
        
188
        $event = new CustomEvent($result->getDecodedJsonData());
189
        $result->setPayload($event);
190
        
191
        return $result;
192
    }
193
}
194
195

lib/WebMarketingROI/OptimizelyPHP/Service/v2/Pages.php 2 locations

@@ 90-105 (lines=16) @@
87
     * Create a new Page in a provided Project
88
     * @param Page $page
89
     */
90
    public function create($page)
91
    {
92
        if (!($page instanceOf Page)) {
93
            throw new Exception("Expected argument of type Page");
94
        }
95
        
96
        $postData = $page->toArray();
97
        
98
        $result = $this->client->sendApiRequest("/pages", array(), 'POST', 
99
                $postData);
100
        
101
        $page = new Page($result->getDecodedJsonData());
102
        $result->setPayload($page);
103
        
104
        return $result;
105
    }
106
    
107
    /**
108
     * Update a Page in a provided Project
@@ 114-129 (lines=16) @@
111
     * @return Result
112
     * @throws Exception
113
     */
114
    public function update($pageId, $page) 
115
    {
116
        if (!($page instanceOf Page)) {
117
            throw new Exception("Expected argument of type Page");
118
        }
119
        
120
        $postData = $page->toArray();
121
                
122
        $result = $this->client->sendApiRequest("/pages/$pageId", array(), 'PATCH', 
123
                $postData);
124
        
125
        $page = new Page($result->getDecodedJsonData());
126
        $result->setPayload($page);
127
        
128
        return $result;
129
    }
130
    
131
    /**
132
     * Delete a Page within a Project by ID.

lib/WebMarketingROI/OptimizelyPHP/Service/v2/Projects.php 1 location

@@ 92-107 (lines=16) @@
89
     * @param Project $project Project meta information.
90
     * @return Result
91
     */
92
    public function create($project)
93
    {
94
        if (!($project instanceOf Project)) {
95
            throw new Exception("Expected argument of type Project");
96
        }
97
        
98
        $postData = $project->toArray();
99
        
100
        $result = $this->client->sendApiRequest("/projects", array(), 'POST', 
101
                $postData);
102
        
103
        $project = new Project($result->getDecodedJsonData());
104
        $result->setPayload($project);
105
        
106
        return $result;
107
    }
108
    
109
    /**
110
     * Update a Project.