Code Duplication    Length = 25-26 lines in 2 locations

src/Console/Commands/PublishAssignment.php 1 location

@@ 139-164 (lines=26) @@
136
     *
137
     * @return array|mixed
138
     */
139
    protected function createAssignment()
140
    {
141
        $url = config('forge-publish.url') . config('forge-publish.store_assignment_uri');
142
        try {
143
            $response = $this->http->post($url, [
144
                'form_params' => [
145
                    'name' => $this->assignmentName,
146
                    'repository_uri' => $this->repository_uri,
147
                    'repository_type' => $this->repository_type,
148
                    'forge_site' => $this->forge_site,
149
                    'forge_server' => $this->forge_server
150
                ],
151
                'headers' => [
152
                    'X-Requested-With' => 'XMLHttpRequest',
153
                    'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN')
154
                ]
155
            ]);
156
        } catch (\Exception $e) {
157
            $this->error('And error occurs connecting to the api url: ' . $url);
158
            $this->error('Status code: ' . $e->getResponse()->getStatusCode() . ' | Reason : ' . $e->getResponse()->getReasonPhrase());
159
            return;
160
        }
161
        $assignment = json_decode((string) $response->getBody());
162
        $this->addValueToEnv('ACACHA_FORGE_ASSIGNMENT', $assignment->id);
163
        return $assignment;
164
    }
165
166
    /**
167
     * Abort command execution.

src/Console/Commands/PublishUpdateAssignment.php 1 location

@@ 130-154 (lines=25) @@
127
     *
128
     * @return array|mixed
129
     */
130
    protected function updateAssignment()
131
    {
132
        $uri = str_replace('{assignment}', $this->assignment, config('forge-publish.update_assignment_uri'));
133
        $url = config('forge-publish.url') . $uri;
134
        try {
135
            $response = $this->http->put($url, [
136
                'form_params' => [
137
                    'name' => $this->assignmentName,
138
                    'repository_uri' => $this->repository_uri,
139
                    'repository_type' => $this->repository_type,
140
                    'forge_site' => $this->forge_site,
141
                    'forge_server' => $this->forge_server
142
                ],
143
                'headers' => [
144
                    'X-Requested-With' => 'XMLHttpRequest',
145
                    'Authorization' => 'Bearer ' . fp_env('ACACHA_FORGE_ACCESS_TOKEN')
146
                ]
147
            ]);
148
        } catch (\Exception $e) {
149
            $this->error('And error occurs connecting to the api url: ' . $url);
150
            $this->error('Status code: ' . $e->getResponse()->getStatusCode() . ' | Reason : ' . $e->getResponse()->getReasonPhrase());
151
            return [];
152
        }
153
        return json_decode((string) $response->getBody());
154
    }
155
156
    /**
157
     * Abort command execution.