Completed
Push — master ( ec9ebd...be73c8 )
by juan
02:23
created

DatabaseService::removeProject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
rs 9.4285
1
<?php
2
3
namespace Juanber84\Services;
4
5
class DatabaseService
6
{
7
    const DIRECTORY = '.dep';
8
    const DB = 'db.json';
9
10
    public function getProjects()
0 ignored issues
show
Coding Style introduced by
getProjects uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
11
    {
12
        $db = file_get_contents($_SERVER['HOME'].'/'.self::DIRECTORY.'/'.self::DB);
13
        $jsonDb = json_decode($db,true);
14
15
        return $jsonDb;
16
    }
17
18
    public function removeProject($keyProject)
19
    {
20
        $jsonDb = $this->getProjects();
21
22
        if (isset($jsonDb[$keyProject])){
23
            unset($jsonDb[$keyProject]);
24
            return true;
25
        } else {
26
            return false;
27
        }
28
    }
29
}