Skip to content

Commit 4b48362

Browse files
committed
cs fixes
1 parent 5c2a309 commit 4b48362

File tree

15 files changed

+343
-256
lines changed

15 files changed

+343
-256
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ Agile Data was designed in a way where all of your code can rely ONLY on model o
125125
This next example builds a complex "Job Profitability Report" by only relying on Model logic:
126126

127127
``` php
128-
class JobReport extends Job {
129-
function init(): void {
128+
class JobReport extends Job
129+
{
130+
protected function init(): void
131+
{
130132
parent::init();
131133

132134
// Invoice contains Lines that may relevant to this job
@@ -359,10 +361,12 @@ If you have enjoyed those examples and would like to try them yourself, continue
359361
Agile Data uses vendor-independent and lightweight `Model` class to describe your business entities:
360362

361363
``` php
362-
class Client extends \Atk4\Data\Model {
364+
class Client extends \Atk4\Data\Model
365+
{
363366
public $table = 'client';
364367

365-
function init(): void {
368+
protected function init(): void
369+
{
366370
parent::init();
367371

368372
$this->addField('name');
@@ -580,7 +584,8 @@ namespace my;
580584
class User extends \Atk4\Data\Model
581585
{
582586
public $table = 'user';
583-
function init(): void
587+
588+
protected function init(): void
584589
{
585590
parent::init();
586591

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"require-release": {
4343
"php": ">=7.4 <8.3",
44-
"atk4/core": "^4.0",
44+
"atk4/core": "~4.0.0",
4545
"doctrine/dbal": "~3.3.0",
4646
"mvorisek/atk4-hintable": "~1.9.0"
4747
},

docs/advanced.rst

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ multiple transaction types. Some of those types would even require additional
1616
fields. The pattern suggest you should add a new table "transaction_transfer" and
1717
store extra fields there. In your code::
1818

19-
class Transaction_Transfer extends Transaction {
20-
function init(): void {
19+
class Transaction_Transfer extends Transaction
20+
{
21+
protected function init(): void {
2122
parent::init();
2223
$j = $this->join('transaction_transfer.transaction_id');
2324
$j->addField('destination_account');
@@ -94,12 +95,13 @@ of the record. Finally to help with performance, you can implement a switch::
9495

9596
...
9697

97-
function init(): void {
98-
..
98+
protected function init(): void
99+
{
100+
...
99101

100102
if ($this->typeSubstitution) {
101103
$this->onHook(Model::HOOK_AFTER_LOAD,
102-
..........
104+
...
103105
)
104106
}
105107
}
@@ -131,7 +133,8 @@ I will be looking to create the following fields:
131133

132134
To implement the above, I'll create a new class::
133135

134-
class ControllerAudit {
136+
class ControllerAudit
137+
{
135138
use \Atk4\Core\InitializerTrait {
136139
init as private _init;
137140
}
@@ -145,7 +148,8 @@ $owner, and $app values (due to AppScopeTrait) as well as execute init() method,
145148
which I want to define like this::
146149

147150

148-
protected function init(): void {
151+
protected function init(): void
152+
{
149153
$this->_init();
150154

151155
if (isset($this->getOwner()->no_audit)) {
@@ -210,13 +214,15 @@ soft-delete controller for Agile Data (for educational purposes).
210214

211215
Start by creating a class::
212216

213-
class ControllerSoftDelete {
217+
class ControllerSoftDelete
218+
{
214219
use \Atk4\Core\InitializerTrait {
215220
init as private _init;
216221
}
217222
use \Atk4\Core\TrackableTrait;
218223

219-
protected function init(): void {
224+
protected function init(): void
225+
{
220226
$this->_init();
221227

222228
if (property_exists($this->getOwner(), 'no_soft_delete')) {
@@ -234,7 +240,8 @@ Start by creating a class::
234240
}
235241
}
236242

237-
public function softDelete(Model $entity) {
243+
public function softDelete(Model $entity)
244+
{
238245
$entity->assertIsLoaded();
239246

240247
$id = $entity->getId();
@@ -249,7 +256,8 @@ Start by creating a class::
249256
return $entity;
250257
}
251258

252-
public function restore(Model $entity) {
259+
public function restore(Model $entity)
260+
{
253261
$entity->assertIsLoaded();
254262

255263
$id = $entity->getId();
@@ -310,14 +318,17 @@ In case you want $m->delete() to perform soft-delete for you - this can also be
310318
achieved through a pretty simple controller. In fact I'm reusing the one from
311319
before and just slightly modifying it::
312320

313-
class ControllerSoftDelete2 extends ControllerSoftDelete {
314-
protected function init(): void {
321+
class ControllerSoftDelete2 extends ControllerSoftDelete
322+
{
323+
protected function init(): void
324+
{
315325
parent::init();
316326

317327
$this->getOwner()->onHook(Model::HOOK_BEFORE_DELETE, \Closure::fromCallable([$this, 'softDelete']), null, 100);
318328
}
319329

320-
public function softDelete(Model $m) {
330+
public function softDelete(Model $m)
331+
{
321332
parent::softDelete();
322333

323334
$m->hook(Model::HOOK_AFTER_DELETE);
@@ -351,15 +362,17 @@ to another user?
351362
With Agile Data you can create controller that will ensure that certain fields
352363
inside your model are unique::
353364

354-
class ControllerUniqueFields {
365+
class ControllerUniqueFields
366+
{
355367
use \Atk4\Core\InitializerTrait {
356368
init as private _init;
357369
}
358370
use \Atk4\Core\TrackableTrait;
359371

360372
protected $fields = null;
361373

362-
function init(): void {
374+
protected function init(): void
375+
{
363376
$this->_init();
364377

365378
// by default make 'name' unique
@@ -370,7 +383,7 @@ inside your model are unique::
370383
$this->getOwner()->onHook(Model::HOOK_BEFORE_SAVE, \Closure::fromCallable([$this, 'beforeSave']));
371384
}
372385

373-
function beforeSave(Model $m)
386+
protected function beforeSave(Model $m)
374387
{
375388
foreach ($this->fields as $field) {
376389
if ($m->getDirtyRef()[$field]) {
@@ -434,10 +447,11 @@ Here is what I need to do:
434447

435448
Create new Model::
436449

437-
class Model_InvoicePayment extends \Atk4\Data\Model {
450+
class Model_InvoicePayment extends \Atk4\Data\Model
451+
{
438452
public $table = 'invoice_payment';
439453

440-
function init(): void
454+
protected function init(): void
441455
{
442456
parent::init();
443457
$this->hasOne('invoice_id', 'Model_Invoice');
@@ -496,7 +510,7 @@ payment towards a most suitable invoice::
496510

497511

498512
// Add to Model_Payment
499-
function autoAllocate()
513+
public function autoAllocate()
500514
{
501515
$client = $this->ref['client_id'];
502516
$invoices = $client->ref('Invoice');
@@ -546,8 +560,10 @@ adding invoice, I want to make it possible to specify 'Category' through the
546560
name, not only category_id. First, let me illustrate how can I do that with
547561
category_id::
548562

549-
class Model_Invoice extends \Atk4\Data\Model {
550-
function init(): void {
563+
class Model_Invoice extends \Atk4\Data\Model
564+
{
565+
protected function init(): void
566+
{
551567
parent::init();
552568

553569
...

docs/conditions.rst

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ to set those conditions inside the init() method of your model::
124124

125125
class Model_Girl extends Model_User
126126
{
127-
function init(): void
127+
protected function init(): void
128128
{
129129
parent::init();
130130

@@ -254,7 +254,7 @@ These classes can be used directly and independently from Model class.
254254
255255
This method provides access to the model scope enabling conditions to be added::
256256

257-
$contact->scope()->addCondition($condition); // adding condition to a model
257+
$contact->scope()->addCondition($condition); // adding condition to a model
258258

259259
.. php:class:: Scope
260260
@@ -264,53 +264,53 @@ e.g ((Name like 'ABC%' and Country = 'US') or (Name like 'CDE%' and (Country = '
264264

265265
Scope can be created using new Scope() statement from an array or joining Condition objects or condition arguments arrays::
266266

267-
// $condition1 will be used as nested condition
268-
$condition1 = new Condition('name', 'like', 'ABC%');
267+
// $condition1 will be used as nested condition
268+
$condition1 = new Condition('name', 'like', 'ABC%');
269269

270-
// $condition2 will converted to Condtion object and used as nested condition
271-
$condition2 = ['country', 'US'];
270+
// $condition2 will converted to Condtion object and used as nested condition
271+
$condition2 = ['country', 'US'];
272272

273-
// $scope1 is created using AND as junction and $condition1 and $condition2 as nested conditions
274-
$scope1 = Scope::createAnd($condition1, $condition2);
273+
// $scope1 is created using AND as junction and $condition1 and $condition2 as nested conditions
274+
$scope1 = Scope::createAnd($condition1, $condition2);
275275

276-
$condition3 = new Condition('country', 'DE');
277-
$condition4 = ['surname', 'XYZ'];
276+
$condition3 = new Condition('country', 'DE');
277+
$condition4 = ['surname', 'XYZ'];
278278

279-
// $scope2 is created using OR as junction and $condition3 and $condition4 as nested conditions
280-
$scope2 = Scope::createOr($condition3, $condition4);
279+
// $scope2 is created using OR as junction and $condition3 and $condition4 as nested conditions
280+
$scope2 = Scope::createOr($condition3, $condition4);
281281

282-
$condition5 = new Condition('name', 'like', 'CDE%');
282+
$condition5 = new Condition('name', 'like', 'CDE%');
283283

284-
// $scope3 is created using AND as junction and $condition5 and $scope2 as nested conditions
285-
$scope3 = Scope::createAnd($condition5, $scope2);
284+
// $scope3 is created using AND as junction and $condition5 and $scope2 as nested conditions
285+
$scope3 = Scope::createAnd($condition5, $scope2);
286286

287-
// $scope is created using OR as junction and $scope1 and $scope3 as nested conditions
288-
$scope = Scope::createOr($scope1, $scope3);
287+
// $scope is created using OR as junction and $scope1 and $scope3 as nested conditions
288+
$scope = Scope::createOr($scope1, $scope3);
289289

290290

291291
Scope is an independent object not related to any model. Applying scope to model is using the Model::scope()->add($condition) method::
292292

293-
$contact->scope()->add($condition); // adding condition to a model
294-
$contact->scope()->add($conditionXYZ); // adding more conditions
293+
$contact->scope()->add($condition); // adding condition to a model
294+
$contact->scope()->add($conditionXYZ); // adding more conditions
295295

296296
.. php:method:: __construct($nestedConditions = [], $junction = Scope::AND);
297297
298298
Creates a Scope object from an array::
299299

300-
// below will create 2 conditions and nest them in a compound conditions with AND junction
301-
$scope1 = new Scope([
302-
['name', 'like', 'ABC%'],
303-
['country', 'US'],
304-
]);
300+
// below will create 2 conditions and nest them in a compound conditions with AND junction
301+
$scope1 = new Scope([
302+
['name', 'like', 'ABC%'],
303+
['country', 'US'],
304+
]);
305305

306306
.. php:method:: negate();
307307
308308
Negate method has behind the full map of conditions so any condition object can be negated, e.g negating '>=' results in '<', etc.
309309
For compound conditionss this method is using De Morgan's laws, e.g::
310310

311-
// using $scope1 defined above
312-
// results in "(Name not like 'ABC%') or (Country does not equal 'US')"
313-
$scope1->negate();
311+
// using $scope1 defined above
312+
// results in "(Name not like 'ABC%') or (Country does not equal 'US')"
313+
$scope1->negate();
314314

315315
.. php:method:: createAnd(...$conditions);
316316
@@ -357,15 +357,15 @@ If $value is omitted as argument then $operator is considered as $value and '='
357357
358358
Negates the condition, e.g::
359359

360-
// results in "name != 'John'"
361-
$condition = (new Condition('name', 'John'))->negate();
360+
// results in "name != 'John'"
361+
$condition = (new Condition('name', 'John'))->negate();
362362

363363
.. php:method:: toWords(Model $model = null);
364364
365365
Converts the condition object to human readable words. Condition must be assigned to a model or model argument provided::
366366

367-
// results in 'Contact where Name is John'
368-
(new Condition('name', 'John'))->toWords($contactModel);
367+
// results in 'Contact where Name is John'
368+
(new Condition('name', 'John'))->toWords($contactModel);
369369

370370
Conditions on Referenced Models
371371
-------------------------------
@@ -375,15 +375,15 @@ Agile Data allows for adding conditions on related models for retrieval of type
375375
Setting conditions on references can be done utilizing the Model::refLink method but there is a shorthand format
376376
directly integrated with addCondition method using "/" to chain the reference names::
377377

378-
$contact->addCondition('company/country', 'US');
378+
$contact->addCondition('company/country', 'US');
379379

380380
This will limit the $contact model to those whose company is in US.
381381
'company' is the name of the reference in $contact model and 'country' is a field in the referenced model.
382382

383383
If a condition must be set directly on the existence or number of referenced records the special symbol "#" can be
384384
utilized to indicate the condition is on the number of records::
385385

386-
$contact->addCondition('company/tickets/#', '>', 3);
386+
$contact->addCondition('company/tickets/#', '>', 3);
387387

388388
This will limit the $contact model to those whose company have more than 3 tickets.
389389
'company' and 'tickets' are the name of the chained references ('company' is a reference in the $contact model and

0 commit comments

Comments
 (0)