Passed
Push — master ( c34bce...f6db7f )
by Artem
01:28
created

UserRepository::table()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Slides\Connector\Auth\Repositories;
4
5
use Illuminate\Support\Facades\Auth;
6
7
/**
8
 * Class UserRepository
9
 *
10
 * @package Slides\Connector\Auth\Repositories
11
 */
12
class UserRepository
13
{
14
    /**
15
     * Retrieve the table name.
16
     *
17
     * @return string
18
     */
19
    public function table()
20
    {
21
        return Auth::getProvider()
22
            ->createModel()
23
            ->getTable();
24
    }
25
26
    /**
27
     * Create a new query.
28
     *
29
     * @return \Illuminate\Database\Query\Builder
30
     */
31
    public function query()
32
    {
33
        return Auth::getProvider()
34
            ->createModel()
35
            ->newQuery();
36
    }
37
38
    /**
39
     * Make a query using a temporary table.
40
     *
41
     * @param string $name
42
     * @param \Closure $table
43
     * @param array $data
44
     * @param \Closure $query
45
     *
46
     * @return mixed
47
     */
48
    public function withTemporaryTable(string $name, \Closure $table, array $data, \Closure $query)
49
    {
50
        \Illuminate\Support\Facades\Schema::create($name, function(\Illuminate\Database\Schema\Blueprint $callback) use ($table) {
51
            $table($callback);
52
            $callback->temporary();
53
        });
54
55
        \Illuminate\Support\Facades\DB::table($name)->insert($data);
56
57
        $results = $query($this->query(), $name);
58
59
        \Illuminate\Support\Facades\Schema::dropIfExists($name);
60
61
        return $results;
62
    }
63
}