-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathVeryCustomize00009ArticlesTable.php
More file actions
96 lines (86 loc) · 2.57 KB
/
VeryCustomize00009ArticlesTable.php
File metadata and controls
96 lines (86 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
declare(strict_types=1);
/**
* Copyright 2020, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2020, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace App\Model\Table;
use Cake\ORM\Entity;
use Cake\ORM\Table;
/**
* Class VeryCustomize00009ArticlesTable
*
* @mixin \App\Model\Behavior\SampleTestCustomMethodBehavior
* @package App\Model\Table
*/
class VeryCustomize00009ArticlesTable extends Table
{
/**
* @inheritDoc
*/
public function initialize(array $config): void
{
parent::initialize($config);
$this->behaviors()->load('SampleTestCustomMethod');
}
/**
* @param \Cake\Datasource\EntityInterface $article
* @return bool
*/
public function fixArticle($article)
{
//logic to clear article
$this->fakeData();
/**
* @var \Cake\ORM\Entity $article
*/
$article = $this->findByTitle('sample')->first();
$article->set('title', 'sample two');
/**
* @var \Cake\ORM\Entity $article
*/
$article = $this->findByTitleAndActive('sample', true)->first();
$article->set('title', 'sample two');
// Test actual (non-magic) findOrCreateBySku method with specific signature (issue #55)
// When called directly on the table (not through association), PHPStan should use the native method
$entityOrCreate = $this->findOrCreateBySku('TEST-SKU', 'Test Value');
$entityOrCreate->set('title', 'Updated Title');
return true;
}
/**
* Return a new sample article
*
* @return \Cake\ORM\Entity
*/
public function newSample()
{
return new Entity(
[
'title' => 'This is my title',
'content' => 'Sample content for test',
],
);
}
/**
* Custom non-magic findOrCreateBySku method with specific signature
*
* @param string $sku
* @param string $foo
* @return \Cake\Datasource\EntityInterface
*/
public function findOrCreateBySku(string $sku, string $foo)
{
/** @var \Cake\ORM\Entity|null $entity */
$entity = $this->findBySku($sku)->first();
if ($entity === null) {
$entity = $this->newEntity(['sku' => $sku, 'foo' => $foo]);
$entity = $this->saveOrFail($entity);
}
return $entity;
}
}