Completed
Push — master ( 292d01...c6d68c )
by AJ
11:06
created

AccessTokensTable::buildRules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * CakePHPify : CakePHP Plugin for Shopify API Authentication
4
 * Copyright (c) Multidimension.al (http://multidimension.al)
5
 * Github : https://github.com/multidimension-al/cakephpify
6
 *
7
 * Licensed under The MIT License
8
 * For full copyright and license information, please see the LICENSE file
9
 * Redistributions of files must retain the above copyright notice.
10
 *
11
 * @copyright (c) Multidimension.al (http://multidimension.al)
12
 * @link      https://github.com/multidimension-al/cakephpify CakePHPify Github
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT License
14
 */
15
16
namespace Multidimensional\Cakephpify\Model\Table;
17
18
use Cake\ORM\Query;
19
use Cake\ORM\RulesChecker;
20
use Cake\ORM\Table;
21
use Cake\Validation\Validator;
22
23
/**
24
 * AccessTokens Model
25
 *
26
 * @method \Shopify\Model\Entity\AccessToken get($primaryKey, $options = [])
27
 * @method \Shopify\Model\Entity\AccessToken newEntity($data = null, array $options = [])
28
 * @method \Shopify\Model\Entity\AccessToken[] newEntities(array $data, array $options = [])
29
 * @method \Shopify\Model\Entity\AccessToken|bool save(\Cake\Datasource\EntityInterface $entity, $options = [])
30
 * @method \Shopify\Model\Entity\AccessToken patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = [])
31
 * @method \Shopify\Model\Entity\AccessToken[] patchEntities($entities, array $data, array $options = [])
32
 * @method \Shopify\Model\Entity\AccessToken findOrCreate($search, callable $callback = null)
33
 */
34
class AccessTokensTable extends Table
35
{
36
37
    /**
38
     * Initialize method
39
     *
40
     * @param  array $config The configuration for the Table.
41
     * @return void
42
     */
43 18
    public function initialize(array $config)
44
    {
45 18
        parent::initialize($config);
46
47
        //$this->table('access_tokens');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
48 18
        $this->displayField('token');
49
        //$this->primaryKey('id');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% 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...
50
51 18
        $this->belongsTo(
52 18
            'Shops',
53
            [
54 18
            'className' => 'Multidimensional/Cakephpify.Shops']
55 18
        );
56 18
    }
57
58
    /**
59
     * Default validation rules.
60
     *
61
     * @param  \Cake\Validation\Validator $validator Validator instance.
62
     * @return \Cake\Validation\Validator
63
     */
64
    public function validationDefault(Validator $validator)
65
    {
66
        $validator
67
            ->integer('id')
68
            ->allowEmpty('id', 'create');
69
70
        $validator
71
            ->requirePresence('api_key', 'create')
72
            ->notEmpty('api_key');
73
74
        $validator
75
            ->requirePresence('shop_id', 'create')
76
            ->notEmpty('shop_id');
77
78
        $validator
79
            ->requirePresence('token', 'create')
80
            ->notEmpty('token')
81
            ->add('token', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
82
83
        $validator
84
            ->dateTime('created_at')
85
            ->requirePresence('created_at', 'create')
86
            ->notEmpty('created_at');
87
88
        $validator
89
            ->dateTime('updated_at')
90
            ->requirePresence('updated_at', 'create')
91
            ->notEmpty('updated_at');
92
93
        $validator
94
            ->dateTime('expired_at')
95
            ->allowEmpty('expired_at');
96
97
        return $validator;
98
    }
99
100
    /**
101
     * Returns a rules checker object that will be used for validating
102
     * application integrity.
103
     *
104
     * @param  \Cake\ORM\RulesChecker $rules The rules object to be modified.
105
     * @return \Cake\ORM\RulesChecker
106
     */
107
    public function buildRules(RulesChecker $rules)
108
    {
109
        $rules->add($rules->isUnique(['token']));
110
111
        return $rules;
112
    }
113
}
114