Completed
Push — master ( 7949b1...be02a5 )
by Nick
07:10
created

ApplyQueryMethodsToBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 8 2
1
<?php
2
3
namespace EloquentJs\Laravel\Listeners;
4
5
use EloquentJs\Laravel\Events\EloquentJsWasCalled;
6
use EloquentJs\Translators\QueryTranslator;
7
8
class ApplyQueryMethodsToBuilder
9
{
10
    /**
11
     * @var QueryTranslator
12
     */
13
    protected $translator;
14
15
    /**
16
     * Create the event listener.
17
     *
18
     * @param QueryTranslator $translator
19
     */
20
    public function __construct(QueryTranslator $translator)
21
    {
22
        $this->translator = $translator;
23
    }
24
25
    /**
26
     * Handle the event.
27
     *
28
     * @param EloquentJsWasCalled $event
29
     * @return void
30
     */
31
    public function handle(EloquentJsWasCalled $event)
32
    {
33
        if ($event->stack) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $event->stack of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
34
            $this->translator->source($event->stack);
35
        }
36
37
        $this->translator->applyTo($event->builder);
38
    }
39
}
40