Completed
Push — master ( 2da105...fd3969 )
by Julien
75:26 queued 63:55
created

BuildersController::createAccount()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 0
loc 27
rs 8.8571
cc 2
eloc 19
nc 2
nop 1
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
    public function createAccount(Request $request)
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