for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @copyright Copyright (c) Flipbox Digital Limited
* @license https://flipboxfactory.com/software/organization/license
* @link https://www.flipboxfactory.com/software/organization/
*/
namespace flipbox\organizations\actions\organizations;
use Craft;
use craft\elements\User;
use flipbox\organizations\elements\Organization;
use yii\db\ActiveRecord;
use yii\web\HttpException;
* @author Flipbox Factory <[email protected]>
* @since 3.0.0
*
* @method ActiveRecord populate(ActiveRecord $record)
trait LookupAssociationTrait
{
* HTTP not found response code
* @return int
protected function statusCodeNotFound(): int
return $this->statusCodeNotFound ?? 404;
statusCodeNotFound
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* @return string
protected function messageNotFound(): string
return $this->messageNotFound ?? 'Unable to find object.';
messageNotFound
* @return null
* @throws HttpException
protected function handleNotFoundResponse()
throw new HttpException(
$this->statusCodeNotFound(),
$this->messageNotFound()
);
* @param string|int $identifier
* @return ORganization|null
protected function findOrganization($identifier)
return Organization::findOne($identifier);
* @return User|null
protected function findUser($identifier)
if (is_numeric($identifier)) {
return Craft::$app->getUsers()->getUserById($identifier);
return Craft::$app->getUsers()->getUserByUsernameOrEmail($identifier);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: