Completed
Push — master ( 076ad5...3005ec )
by AJ
14:22
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 5
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
    public function initialize(array $config)
44
    {
45
        parent::initialize($config);
46
47
        //$this->table('access_tokens');
48
        $this->displayField('token');
49
        //$this->primaryKey('id');
50
51
        $this->belongsTo('Shops', [
52
            'className' => 'Multidimensional/Cakephpify.Shops']);
53
    }
54
55
    /**
56
     * Default validation rules.
57
     *
58
     * @param \Cake\Validation\Validator $validator Validator instance.
59
     * @return \Cake\Validation\Validator
60
     */
61
    public function validationDefault(Validator $validator)
62
    {
63
        $validator
64
            ->integer('id')
65
            ->allowEmpty('id', 'create');
66
67
        $validator
68
            ->requirePresence('api_key', 'create')
69
            ->notEmpty('api_key');
70
71
        $validator
72
            ->requirePresence('shop_id', 'create')
73
            ->notEmpty('shop_id');
74
75
        $validator
76
            ->requirePresence('token', 'create')
77
            ->notEmpty('token')
78
            ->add('token', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);
79
80
        $validator
81
            ->dateTime('created_at')
82
            ->requirePresence('created_at', 'create')
83
            ->notEmpty('created_at');
84
85
        $validator
86
            ->dateTime('updated_at')
87
            ->requirePresence('updated_at', 'create')
88
            ->notEmpty('updated_at');
89
90
        $validator
91
            ->dateTime('expired_at')
92
            ->allowEmpty('expired_at');
93
94
        return $validator;
95
    }
96
97
    /**
98
     * Returns a rules checker object that will be used for validating
99
     * application integrity.
100
     *
101
     * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
102
     * @return \Cake\ORM\RulesChecker
103
     */
104
    public function buildRules(RulesChecker $rules)
105
    {
106
        $rules->add($rules->isUnique(['token']));
107
108
        return $rules;
109
    }
110
}
111