Completed
Push — master ( 307d8a...2c7bf4 )
by Phecho
05:31
created

ApiController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
c 2
b 1
f 0
lcom 0
cbo 2
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A postUpdateProject() 0 8 2
A postUpdateProjectOrder() 0 11 2
A postUploadAvatar() 0 8 1
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gitamin\Http\Controllers\Dashboard;
13
14
use Exception;
15
use Gitamin\Models\Project;
16
use GrahamCampbell\Binput\Facades\Binput;
17
use Illuminate\Routing\Controller;
18
19
class ApiController extends Controller
20
{
21
    /**
22
     * Updates a project with the entered info.
23
     *
24
     * @param \Gitamin\Models\Project $project
25
     *
26
     * @throws \Exception
27
     *
28
     * @return \Gitamin\Models\Project
29
     */
30
    public function postUpdateProject(Project $project)
31
    {
32
        if (! $project->update(Binput::except(['_token']))) {
33
            throw new Exception(trans('dashboard.projects.edit.failure'));
34
        }
35
36
        return $project;
37
    }
38
39
    /**
40
     * Updates a projects ordering.
41
     *
42
     * @return array
43
     */
44
    public function postUpdateProjectOrder()
45
    {
46
        $projectData = Binput::get('ids');
47
48
        foreach ($projectData as $order => $projectId) {
49
            // Ordering should be 1-based, data comes in 0-based
50
            Project::find($projectId)->update(['order' => $order + 1]);
51
        }
52
53
        return $projectData;
54
    }
55
56
    public function postUploadAvatar()
57
    {
58
        $data = [
59
            'path' => '/img/no_group_avatar.png',
60
        ];
61
62
        return $data;
63
    }
64
}
65