Completed
Push — master ( 740d41...a3b506 )
by Michal
07:10 queued 16s
created

NotificationsTable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

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