GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Todo::create()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 3
eloc 14
nc 3
nop 2
1
<?php
2
 
3
 /**
4
  * Todo Class
5
  *
6
  * @license    http://opensource.org/licenses/MIT The MIT License (MIT)
7
  * @author     Omar El Gabry <[email protected]>
8
  */
9
10
class Todo extends Model{
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
12 View Code Duplication
    public function getAll(){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
14
        $database = Database::openConnection();
15
        $query  = "SELECT todo.id AS id, users.id AS user_id, users.name AS user_name, todo.content ";
16
        $query .= "FROM users, todo ";
17
        $query .= "WHERE users.id = todo.user_id ";
18
19
        $database->prepare($query);
20
        $database->execute();
21
        $todo = $database->fetchAllAssociative();
22
23
        return $todo;
24
     }
25
26
    public function create($userId, $content){
27
28
        // using validation class
29
        $validation = new Validation();
30
        if(!$validation->validate(['Content'   => [$content, "required|minLen(4)|maxLen(300)"]])) {
31
            $this->errors = $validation->errors();
32
            return false;
33
        }
34
35
        // using database class to insert new todo
36
        $database = Database::openConnection();
37
        $query    = "INSERT INTO todo (user_id, content) VALUES (:user_id, :content)";
38
        $database->prepare($query);
39
        $database->bindValue(':user_id', $userId);
40
        $database->bindValue(':content', $content);
41
        $database->execute();
42
43
        if($database->countRows() !== 1){
44
            throw new Exception("Couldn't create todo");
45
        }
46
47
        return true;
48
     }
49
50 View Code Duplication
    public function delete($id){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
52
        $database = Database::openConnection();
53
        $database->deleteById("todo", $id);
54
55
        if($database->countRows() !== 1){
56
            throw new Exception ("Couldn't delete todo");
57
        }
58
    }
59
 }