Completed
Push — master ( 70ed4c...f56a68 )
by Ievgen
05:07 queued 03:10
created

UpdateOperation::notifyAdmin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use einfach\operation\Railway;
4
use function einfach\operation\response\ok;
5
use function einfach\operation\response\error;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, error.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
7
class UpdateOperation implements \einfach\operation\IOperation
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * @param $params
11
     * @return \einfach\operation\Result
12
     */
13
    public function __invoke($params)
14
    {
15
        $result = (new Railway)
16
            ->step(function ($params) {
17
                echo "Hey {$params['name']}. Say hello to anonymous function!";
18
                //return error('Early fail');
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
19
                return ok(['newParam' => 'newValue']);
20
            })
21
            ->step([$this, 'nestedRailway'])
22
            ->step([$this, 'castRequest'])
23
            ->step([$this, 'validateRequest'])
24
            ->step([$this, 'findUser'])
25
            ->step([$this, 'updateDB'])
26
            ->tryCatch([$this, 'sendNotification'])
27
            ->always([$this, 'writeLog'])
28
            ->failure([$this, 'notifyAdmin'])
29
            ->runWithParams($params);
30
31
        return $result;
32
    }
33
34
    public function nestedRailway($params){
35
        return (new Railway)
36
            ->step(function ($params){
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
                //return error('Nested Railway failed!');
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
                return ok(['nestedRwParam' => 'nestedRwValue']);
39
            })
40
            ->runWithParams($params);
41
    }
42
43
    public function castRequest($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        return ok();
46
    }
47
48
    public function validateRequest($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        return ok();
51
    }
52
53
    public function findUser($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        // pretend I am doing a query
56
        // $user = DB::findById($params['id']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
57
        $user = (object) ['id' => 123, 'name' => 'Eugene', 'phone' => '111111'];
58
       return ok(['model' => $user]);
59
        //return error('User not found!');
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
    }
61
62
    public function updateDB($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        return ok();
65
    }
66
67
    public function sendNotification($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69
        //throw new \Exception("Hey there, Exception!");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
        return ok();
71
    }
72
73
    public function writeLog($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
76
    }
77
78
    public function notifyAdmin($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
79
    {
80
81
    }
82
}
83
84
85
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
86
87
$castRequest = castRequest($request);   // always success (one-way track) // Success
88
$validRequest = validateRequest($castRequest);  // true or false (two ways tracks)  // Step
89
$dbResult = updateDB($validRequest);  // does not return (dead-end track) // Step
90
sendNotification($dbResult, $validRequest);  // try catch // TryCatch
91
writeLog($dbResult, $validRequest); // supervisory (do smth for both tracks) // Proxy
92
render($dbResult, $validRequest);
93
94
*/
95
96
97
//->wrap(function ($params) use ($dbConn) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
//    /** @var $pipe Pipe */
99
//    $params['dbConn'] = $dbConn;
100
//
101
//    return Pipe::with($params)
102
//        ->tryCatch(function ($params) {
103
//            return $params['dbConn']->beginTransaction();
104
//        })
105
//        ->step(function ($params) {
106
//            return $params['dbConn']->createCommand('SQL #1')->execute();
107
//        })
108
//        ->step(function ($params) {
109
//            return $params['dbConn']->createCommand('SQL #2')->execute();
110
//        })
111
//        ->tryCatch(function ($params) {
112
//            return $params['transaction']->commit();
113
//        })
114
//        ->fail(function ($params) {
115
//            return $params['transaction']->rollBack();
116
//        })
117
//        ->run();
118
//})
119