Completed
Push — develop-3.0 ( 4fe777...24fc5d )
by Mohamed
09:15
created

Updater::updateMessagesSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Repository\User;
13
14
use Hash;
15
use Tinyissue\Contracts\Model\UserInterface;
16
use Tinyissue\Model\Project\User as ProjectUser;
17
use Tinyissue\Model\User;
18
use Tinyissue\Repository\RepositoryUpdater;
19
20
/**
21
 * Class Updater.
22
 *
23
 * @package Tinyissue\\User
24
 */
25
class Updater extends RepositoryUpdater
26
{
27
    protected $model;
28
29
    public function __construct(UserInterface $model)
30
    {
31
        $this->model = $model;
32
    }
33
34
    /**
35
     * Add a new user.
36
     *
37
     * @param array $info
38
     *
39
     * @return bool
40
     */
41 View Code Duplication
    public function create(array $info)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $insert = [
44
            'email'     => $info['email'],
45
            'firstname' => $info['firstname'],
46
            'lastname'  => $info['lastname'],
47
            'role_id'   => $info['role_id'],
48
            'private'   => (boolean) $info['private'],
49
            'password'  => Hash::make($info['password']),
50
            'status'    => $info['status'],
51
            'language'  => app('tinyissue.settings')->getLanguage(),
52
        ];
53
54
        return $this->model->fill($insert)->save();
55
    }
56
57
    /**
58
     * Soft deletes a user and empties the email.
59
     *
60
     * @return bool
61
     */
62 View Code Duplication
    public function delete()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $this->model->update([
65
            'email'   => $this->model->email . '_deleted',
0 ignored issues
show
Bug introduced by
Accessing email on the interface Tinyissue\Contracts\Model\UserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
66
            'deleted' => User::DELETED_USERS,
67
        ]);
68
69
        ProjectUser::where('user_id', '=', $this->model->id)->delete();
0 ignored issues
show
Bug introduced by
Accessing id on the interface Tinyissue\Contracts\Model\UserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
70
71
        return true;
72
    }
73
74
    /**
75
     * Updates the users settings, validates the fields.
76
     *
77
     * @param array $info
0 ignored issues
show
Bug introduced by
There is no parameter named $info. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
78
     *
79
     * @return Eloquent\Model
80
     */
81 View Code Duplication
    public function update(array $attributes = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        if ($attributes['password']) {
84
            $attributes['password'] = Hash::make($attributes['password']);
85
        } elseif (empty($attributes['password'])) {
86
            unset($attributes['password']);
87
        }
88
89
        return $this->model->update($attributes);
90
    }
91
92
    /**
93
     * Update user messages setting.
94
     *
95
     * @param array $input
96
     */
97 View Code Duplication
    public function updateMessagesSettings(array $input)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        return (new ProjectUser())
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Tinyissue\Model\Project\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
100
            ->where('user_id', '=', $this->model->id)
0 ignored issues
show
Bug introduced by
Accessing id on the interface Tinyissue\Contracts\Model\UserInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
101
            ->whereIn('project_id', array_keys($input))
102
            ->get()
103
            ->each(function (ProjectUser $project) use ($input) {
104
                $project->message_id = $input[$project->project_id];
105
                $project->save();
106
            });
107
    }
108
}
109