Completed
Push — master ( aed5b3...caff4d )
by Michal
05:21
created

NotificationsTable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 94.44%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 69
ccs 17
cts 18
cp 0.9444
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 7 1
A addNotifications() 0 19 3
1
<?php
2
3
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
/**
5
 * Notification model representing a notification for new report.
6
 *
7
 * phpMyAdmin Error reporting server
8
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
15
 * @license   https://opensource.org/licenses/mit-license.php MIT License
16
 *
17
 * @see      https://www.phpmyadmin.net/
18
 */
19
20
namespace App\Model\Table;
21
22
use Cake\Model\Model;
23
use Cake\ORM\Table;
24
use Cake\ORM\TableRegistry;
25
26
/**
27
 * Notification Model.
28
 *
29
 * @property Developer $Developer
30
 * @property Report    $Report
31
 */
32
class NotificationsTable extends Table
33
{
34
    /**
35
     * Validation rules.
36
     *
37
     * @var array
38
     */
39
    public $validate = array(
40
        'developer_id' => array(
41
            'numeric' => array(
42
                'rule' => array('numeric'),
43
                'allowEmpty' => false,
44
                'required' => true,
45
            ),
46
        ),
47
        'report_id' => array(
48
            'numeric' => array(
49
                'rule' => array('numeric'),
50
                'allowEmpty' => false,
51
                'required' => true,
52
            ),
53
        ),
54
    );
55
56
    /**
57
     * The Associations below have been created with all possible keys,
58
     * those that are not needed can be removed.
59
     */
60
61
    /**
62
     * belongsTo associations.
63
     *
64
     * @var array
65
     */
66 9
    public function initialize(array $config)
67
    {
68 9
        $this->belongsTo('Reports', array(
69 9
            'className' => 'Reports',
70
            'foreignKey' => 'report_id',
71
        ));
72 9
    }
73
74
    /**
75
     * To Add Multiple Notifications for New report.
76
     *
77
     * @param int $report_id id of the new Report
78
     *
79
     * @return bool value. True on success. False on any type of failure.
80
     */
81 3
    public static function addNotifications($report_id)
82
    {
83 3
        if (!is_int($report_id)) {
84
            throw new InvalidArgumentException('Invalid Argument "$report_id"! Integer Expected.');
85
        }
86 3
        $devs = TableRegistry::get('Developers')->find('all');
87 3
        $notoficationTable = TableRegistry::get('Notifications');
88 3
        $res = true;
89 3
        foreach ($devs as $dev) {
90 3
            $notification = $notoficationTable->newEntity();
91 3
            $notification->developer_id = $dev['id'];
0 ignored issues
show
Bug introduced by
Accessing developer_id on the interface Cake\Datasource\EntityInterface 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...
92 3
            $notification->report_id = $report_id;
0 ignored issues
show
Bug introduced by
Accessing report_id on the interface Cake\Datasource\EntityInterface 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...
93 3
            $notification->created = date('Y-m-d H:i:s', time());
0 ignored issues
show
Bug introduced by
Accessing created on the interface Cake\Datasource\EntityInterface 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...
94 3
            $notification->modified = date('Y-m-d H:i:s', time());
0 ignored issues
show
Bug introduced by
Accessing modified on the interface Cake\Datasource\EntityInterface 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...
95 3
            $res = $notoficationTable->save($notification);
96
        }
97
98 3
        return $res;
99
    }
100
}
101