Passed
Push — next ( 3b41f7...f014dd )
by Bas
02:34
created

UsesBlueprints   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 64
ccs 19
cts 19
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A table() 0 3 1
A createBlueprint() 0 10 2
A build() 0 3 1
A create() 0 6 1
A blueprintResolver() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\Aranguent\Schema\Concerns;
6
7
use LaravelFreelancerNL\Aranguent\Schema\Blueprint;
8
9
trait UsesBlueprints
10
{
11
    /**
12
     * Create a new command set with a Closure.
13
     *
14
     * @param string        $collection
15
     * @param \Closure|null $callback
16
     *
17
     * @return Blueprint
18
     */
19 122
    protected function createBlueprint($collection, \Closure $callback = null)
20
    {
21
        //Prefixes are unnamed in ArangoDB
22 122
        $prefix = null;
23
24 122
        if (isset($this->resolver)) {
25 1
            return call_user_func($this->resolver, $collection, $this->schemaManager, $callback, $prefix);
26
        }
27
28 122
        return new Blueprint($collection, $this->schemaManager, $callback, $prefix);
29
    }
30
31
    /**
32
     * Set the Schema Blueprint resolver callback.
33
     *
34
     * @param Closure $resolver
0 ignored issues
show
Bug introduced by
The type LaravelFreelancerNL\Aran...Schema\Concerns\Closure was not found. Did you mean Closure? If so, make sure to prefix the type with \.
Loading history...
35
     *
36
     * @return void
37
     */
38 1
    public function blueprintResolver(\Closure $resolver)
39
    {
40 1
        $this->resolver = $resolver;
0 ignored issues
show
Bug Best Practice introduced by
The property resolver does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
41 1
    }
42
43 122
    protected function build($blueprint)
44
    {
45 122
        $blueprint->build($this->connection, $this->grammar);
46 122
    }
47
48
    /**
49
     * Create a new collection on the schema.
50
     *
51
     * @param array<mixed> $config
52
     */
53 122
    public function create($table, \Closure $callback, array $config = []): void
54
    {
55 122
        $this->build(tap($this->createBlueprint($table), function ($blueprint) use ($callback, $config) {
56 122
            $blueprint->create($config);
57
58 122
            $callback($blueprint);
59 122
        }));
60 122
    }
61
62
    /**
63
     * Modify a table's schema.
64
     *
65
     * @param string  $table
66
     * @param \Closure $callback
67
     *
68
     * @return void
69
     */
70 9
    public function table($table, \Closure $callback)
71
    {
72 9
        $this->build($this->createBlueprint($table, $callback));
73 9
    }
74
}
75