Completed
Push — master ( fd3969...5d14d5 )
by Julien
09:12
created

BuildersController::listAccount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
use Illuminate\Http\Request;
5
6
7
/**
8
 * Class BuildersController.
9
 */
10
class BuildersController extends Controller
11
{
12
13
    /**
14
     * Create account
15
     */
16 View Code Duplication
    public function createAccount(Request $request)
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...
17
    {
18
        $data = [
19
          "name" => $request->name,
20
          "cp" => $request->cp,
21
          "phone" => $request->phone,
22
          "sexe" => $request->sexe,
23
          "news" => $request->news,
24
        ];
25
26
        $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
27
        $collection = new \MongoDB\Collection($manager, 'builders', 'account');
28
        $stat = [
29
            'email'    => $request->email,
30
            'data'    => $data,
31
            'created' => new  \DateTime("now"),
32
        ];
33
34
        try{
35
            $collection->insertOne($stat);
36
        }catch (\Exception $e){
37
            return response()->json(['state' => false]);
38
        }
39
40
        $data["email"] = $request->email;
1 ignored issue
show
Bug introduced by
The property email does not seem to exist in Illuminate\Http\Request.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
41
        return response()->json(['data' => $data, 'state' => true]);
42
    }
43
44
    /**
45
     * List account
46
     */
47
    public function listAccount()
48
    {
49
        $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
50
        $collection = new \MongoDB\Collection($manager, 'builders', 'account');
51
52
        $result = $collection->find()->toArray();
53
54
        $tab = [];
55
        foreach($result as $one){
56
            $tab[] = $one->bsonSerialize();
57
        }
58
59
        return response()->json($tab);
60
    }
61
62
    /**
63
     * Update account
64
     */
65 View Code Duplication
    public function updateAccount(Request $request)
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...
66
    {
67
        $data = [
68
          "name" => $request->name,
69
          "cp" => $request->cp,
70
          "phone" => $request->phone,
71
          "sexe" => $request->sexe,
72
          "news" => $request->news,
73
        ];
74
75
        $manager = new \MongoDB\Driver\Manager('mongodb://localhost:27017');
76
        $collection = new \MongoDB\Collection($manager, 'builders', 'account');
77
        $stat = [
78
            'email'    => $request->email,
79
            'data'    => $data,
80
            'created' => new  \DateTime("now"),
81
        ];
82
83
        try{
84
            $collection->updateOne(["email" => $request->email], $stat);
85
        }catch (\Exception $e){
86
            return response()->json(['state' => false]);
87
        }
88
89
        $data["email"] = $request->email;
1 ignored issue
show
Bug introduced by
The property email does not seem to exist in Illuminate\Http\Request.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
90
        return response()->json(['data' => $data, 'state' => true]);
91
    }
92
93
}
94