Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like RecordEntity often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RecordEntity, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class RecordEntity extends SchematicEntity implements RecordInterface |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * Static container fallback. |
||
| 34 | */ |
||
| 35 | use SaturateTrait; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Field format declares how entity must process magic setters and getters. Available values: |
||
| 39 | * camelCase, tableize. |
||
| 40 | */ |
||
| 41 | const FIELD_FORMAT = 'tableize'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * We are going to inherit parent validation rules, this will let spiral translator know about |
||
| 45 | * it and merge i18n messages. |
||
| 46 | * |
||
| 47 | * @see TranslatorTrait |
||
| 48 | */ |
||
| 49 | const I18N_INHERIT_MESSAGES = true; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * ORM records are be divided by two sections: active and passive records. When record is active |
||
| 53 | * ORM allowed to modify associated record table using declared schema and created relations. |
||
| 54 | * |
||
| 55 | * Passive records (ACTIVE_SCHEMA = false) however can only read table schema from database and |
||
| 56 | * forbidden to do any schema modification either by record or by relations. |
||
| 57 | * |
||
| 58 | * You can use ACTIVE_SCHEMA = false in cases where you need to create an ActiveRecord for |
||
| 59 | * existed table. |
||
| 60 | * |
||
| 61 | * @see RecordSchema |
||
| 62 | * @see \Spiral\ORM\Entities\SchemaBuilder |
||
| 63 | */ |
||
| 64 | const ACTIVE_SCHEMA = true; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Indication that record were deleted. |
||
| 68 | */ |
||
| 69 | const DELETED = 900; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Default ORM relation types, see ORM configuration and documentation for more information, |
||
| 73 | * i had to remove 200 lines of comments to make record little bit smaller. |
||
| 74 | * |
||
| 75 | * @see RelationSchemaInterface |
||
| 76 | * @see RelationSchema |
||
| 77 | */ |
||
| 78 | const HAS_ONE = 101; |
||
| 79 | const HAS_MANY = 102; |
||
| 80 | const BELONGS_TO = 103; |
||
| 81 | const MANY_TO_MANY = 104; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Morphed relation types are usually created by inversion or equivalent of primary relation |
||
| 85 | * types. |
||
| 86 | * |
||
| 87 | * @see RelationSchemaInterface |
||
| 88 | * @see RelationSchema |
||
| 89 | * @see MorphedRelation |
||
| 90 | */ |
||
| 91 | const BELONGS_TO_MORPHED = 108; |
||
| 92 | const MANY_TO_MORPHED = 109; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Constants used to declare relations in record schema, used in normalized relation schema. |
||
| 96 | * |
||
| 97 | * @see RelationSchemaInterface |
||
| 98 | */ |
||
| 99 | const OUTER_KEY = 901; //Outer key name |
||
| 100 | const INNER_KEY = 902; //Inner key name |
||
| 101 | const MORPH_KEY = 903; //Morph key name |
||
| 102 | const PIVOT_TABLE = 904; //Pivot table name |
||
| 103 | const PIVOT_COLUMNS = 905; //Pre-defined pivot table columns |
||
| 104 | const PIVOT_DEFAULTS = 906; //Pre-defined pivot table default values |
||
| 105 | const THOUGHT_INNER_KEY = 907; //Pivot table options |
||
| 106 | const THOUGHT_OUTER_KEY = 908; //Pivot table options |
||
| 107 | const WHERE = 909; //Where conditions |
||
| 108 | const WHERE_PIVOT = 910; //Where pivot conditions |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Additional constants used to control relation schema behaviour. |
||
| 112 | * |
||
| 113 | * @see Record::$schema |
||
| 114 | * @see RelationSchemaInterface |
||
| 115 | */ |
||
| 116 | const INVERSE = 1001; //Relation should be inverted to parent record |
||
| 117 | const CONSTRAINT = 1002; //Relation should create foreign keys (default) |
||
| 118 | const CONSTRAINT_ACTION = 1003; //Default relation foreign key delete/update action (CASCADE) |
||
| 119 | const CREATE_PIVOT = 1004; //Many-to-Many should create pivot table automatically (default) |
||
| 120 | const NULLABLE = 1005; //Relation can be nullable (default) |
||
| 121 | const CREATE_INDEXES = 1006; //Indication that relation is allowed to create required indexes |
||
| 122 | const MORPHED_ALIASES = 1007; //Aliases for morphed sub-relations |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Relations marked as embedded will be automatically saved/validated with parent model. In |
||
| 126 | * addition such models data can be set using setFields method (only for ONE relations). |
||
| 127 | * |
||
| 128 | * @see setFields() |
||
| 129 | * @see save() |
||
| 130 | * @see validate() |
||
| 131 | */ |
||
| 132 | const EMBEDDED_RELATION = 1008; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Constants used to declare indexes in record schema. |
||
| 136 | * |
||
| 137 | * @see Record::$indexes |
||
| 138 | */ |
||
| 139 | const INDEX = 1000; //Default index type |
||
| 140 | const UNIQUE = 2000; //Unique index definition |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Errors in relations and acessors. |
||
| 144 | * |
||
| 145 | * @var array |
||
| 146 | */ |
||
| 147 | private $nestedErrors = []; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Indicates that record data were loaded from database (not recently created). |
||
| 151 | * |
||
| 152 | * @var bool |
||
| 153 | */ |
||
| 154 | private $loaded = false; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Schema provided by ORM component. |
||
| 158 | * |
||
| 159 | * @var array |
||
| 160 | */ |
||
| 161 | private $ormSchema = []; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * SolidState will force record data to be saved as one big update set without any generating |
||
| 165 | * separate update statements for changed columns. |
||
| 166 | * |
||
| 167 | * @var bool |
||
| 168 | */ |
||
| 169 | private $solidState = false; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Populated when record loaded using many-to-many connection. Property will include every |
||
| 173 | * column of connection row in pivot table. |
||
| 174 | * |
||
| 175 | * @see setContext() |
||
| 176 | * @see getPivot(); |
||
| 177 | * @var array |
||
| 178 | */ |
||
| 179 | private $pivotData = []; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Record field updates (changed values). |
||
| 183 | * |
||
| 184 | * @var array |
||
| 185 | */ |
||
| 186 | private $updates = []; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Constructed and pre-cached set of record relations. Relation will be in a form of data array |
||
| 190 | * to be created on demand. |
||
| 191 | * |
||
| 192 | * @see relation() |
||
| 193 | * @see __call() |
||
| 194 | * @see __set() |
||
| 195 | * @see __get() |
||
| 196 | * @var RelationInterface[]|array |
||
| 197 | */ |
||
| 198 | protected $relations = []; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Table name (without database prefix) record associated to, RecordSchema will generate table |
||
| 202 | * name automatically using class name, however i'm strongly recommend to declare table name |
||
| 203 | * manually as it gives more readable code. |
||
| 204 | * |
||
| 205 | * @var string |
||
| 206 | */ |
||
| 207 | protected $table = null; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Database name/id where record table located in. By default database will be used if nothing |
||
| 211 | * else is specified. |
||
| 212 | * |
||
| 213 | * @var string|null |
||
| 214 | */ |
||
| 215 | protected $database = null; |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Set of indexes to be created for associated record table, indexes only created when record is |
||
| 219 | * not abstract and has active schema set to true. |
||
| 220 | * |
||
| 221 | * Use constants INDEX and UNIQUE to describe indexes, you can also create compound indexes: |
||
| 222 | * protected $indexes = [ |
||
| 223 | * [self::UNIQUE, 'email'], |
||
| 224 | * [self::INDEX, 'board_id'], |
||
| 225 | * [self::INDEX, 'board_id', 'check_id'] |
||
| 226 | * ]; |
||
| 227 | * |
||
| 228 | * @var array |
||
| 229 | */ |
||
| 230 | protected $indexes = []; |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Record relations and columns can be described in one place - record schema. |
||
| 234 | * Attention: while defining table structure make sure that ACTIVE_SCHEMA constant is set to t |
||
| 235 | * rue. |
||
| 236 | * |
||
| 237 | * Example: |
||
| 238 | * protected $schema = [ |
||
| 239 | * 'id' => 'primary', |
||
| 240 | * 'name' => 'string', |
||
| 241 | * 'biography' => 'text' |
||
| 242 | * ]; |
||
| 243 | * |
||
| 244 | * You can pass additional options for some of your columns: |
||
| 245 | * protected $schema = [ |
||
| 246 | * 'pinCode' => 'string(128)', //String length |
||
| 247 | * 'status' => 'enum(active, hidden)', //Enum values |
||
| 248 | * 'balance' => 'decimal(10, 2)' //Decimal size and precision |
||
| 249 | * ]; |
||
| 250 | * |
||
| 251 | * Every created column will be stated as NOT NULL with forced default value, if you want to |
||
| 252 | * have nullable columns, specify special data key: protected $schema = [ |
||
| 253 | * 'name' => 'string, nullable' |
||
| 254 | * ]; |
||
| 255 | * |
||
| 256 | * You can easily combine table and relations definition in one schema: |
||
| 257 | * protected $schema = [ |
||
| 258 | * |
||
| 259 | * //Table schema |
||
| 260 | * 'id' => 'bigPrimary', |
||
| 261 | * 'name' => 'string', |
||
| 262 | * 'email' => 'string', |
||
| 263 | * 'phoneNumber' => 'string(32)', |
||
| 264 | * |
||
| 265 | * //Relations |
||
| 266 | * 'profile' => [ |
||
| 267 | * self::HAS_ONE => 'Records\Profile', |
||
| 268 | * self::INVERSE => 'user' |
||
| 269 | * ], |
||
| 270 | * 'roles' => [ |
||
| 271 | * self::MANY_TO_MANY => 'Records\Role', |
||
| 272 | * self::INVERSE => 'users' |
||
| 273 | * ] |
||
| 274 | * ]; |
||
| 275 | * |
||
| 276 | * @var array |
||
| 277 | */ |
||
| 278 | protected $schema = []; |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Default field values. |
||
| 282 | * |
||
| 283 | * @var array |
||
| 284 | */ |
||
| 285 | protected $defaults = []; |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @invisible |
||
| 289 | * @var ORM |
||
| 290 | */ |
||
| 291 | protected $orm = null; |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Due setContext() method and entity cache of ORM any custom initiation code in constructor |
||
| 295 | * must not depends on database data. |
||
| 296 | * |
||
| 297 | * @see setContext |
||
| 298 | * @param array $data |
||
| 299 | * @param bool|false $loaded |
||
| 300 | * @param ORM|null $orm |
||
| 301 | * @param array $ormSchema |
||
| 302 | * @throws SugarException |
||
| 303 | */ |
||
| 304 | public function __construct( |
||
| 305 | array $data = [], |
||
| 306 | $loaded = false, |
||
| 307 | ORM $orm = null, |
||
| 308 | array $ormSchema = [] |
||
| 309 | ) { |
||
| 310 | $this->loaded = $loaded; |
||
| 311 | |||
| 312 | //We can use global container as fallback if no default values were provided |
||
| 313 | $this->orm = $this->saturate($orm, ORM::class); |
||
| 314 | |||
| 315 | $this->ormSchema = !empty($ormSchema) ? $ormSchema : $this->orm->schema(static::class); |
||
| 316 | |||
| 317 | if (isset($data[ORM::PIVOT_DATA])) { |
||
| 318 | $this->pivotData = $data[ORM::PIVOT_DATA]; |
||
| 319 | unset($data[ORM::PIVOT_DATA]); |
||
| 320 | } |
||
| 321 | |||
| 322 | foreach (array_intersect_key($data, |
||
| 323 | $this->ormSchema[ORM::M_RELATIONS]) as $name => $relation) { |
||
| 324 | $this->relations[$name] = $relation; |
||
| 325 | unset($data[$name]); |
||
| 326 | } |
||
| 327 | |||
| 328 | //Data is initiated as default values and non default |
||
| 329 | parent::__construct($data + $this->ormSchema[ORM::M_COLUMNS], $this->ormSchema); |
||
| 330 | |||
| 331 | if (!$this->isLoaded()) { |
||
| 332 | //Non loaded records should be in solid state by default and require initial validation |
||
| 333 | $this->solidState(true)->invalidate(); |
||
| 334 | } |
||
| 335 | } |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Record context must be updated in cases where single record instance can be accessed from |
||
| 339 | * multiple places, context will not change record fields but might overwrite pivot data or |
||
| 340 | * clarify loaded relations. |
||
| 341 | * |
||
| 342 | * @param array $context |
||
| 343 | * @return $this |
||
| 344 | */ |
||
| 345 | public function setContext(array $context) |
||
| 346 | { |
||
| 347 | //Mounting context pivot data |
||
| 348 | $this->pivotData = isset($context[ORM::PIVOT_DATA]) ? $context[ORM::PIVOT_DATA] : []; |
||
| 349 | |||
| 350 | $relations = array_intersect_key($context, $this->ormSchema[ORM::M_RELATIONS]); |
||
| 351 | foreach ($relations as $name => $relation) { |
||
| 352 | if (!isset($this->relations[$name]) || is_array($this->relations[$name])) { |
||
| 353 | //Does not exists and never requested before |
||
| 354 | $this->relations[$name] = $relation; |
||
| 355 | continue; |
||
| 356 | } |
||
| 357 | |||
| 358 | //We have to reset relation state to update context |
||
| 359 | $this->relations[$name]->reset($relation, true); |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * We are not going to update record fields. |
||
| 364 | */ |
||
| 365 | |||
| 366 | return $this; |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Change record solid state. SolidState will force record data to be saved as one big update |
||
| 371 | * set without any generating separate update statements for changed columns. |
||
| 372 | * |
||
| 373 | * Attention, you have to carefully use forceUpdate flag with records without primary keys due |
||
| 374 | * update criteria (WHERE condition) can not be easy constructed for records with primary key. |
||
| 375 | * |
||
| 376 | * @param bool $solidState |
||
| 377 | * @param bool $forceUpdate Mark all fields as changed to force update later. |
||
| 378 | * @return $this |
||
| 379 | */ |
||
| 380 | public function solidState($solidState, $forceUpdate = false) |
||
| 381 | { |
||
| 382 | $this->solidState = $solidState; |
||
| 383 | |||
| 384 | if ($forceUpdate) { |
||
| 385 | if ($this->ormSchema[ORM::M_PRIMARY_KEY]) { |
||
| 386 | $this->updates = $this->stateCriteria(); |
||
| 387 | } else { |
||
| 388 | $this->updates = $this->ormSchema[ORM::M_COLUMNS]; |
||
| 389 | } |
||
| 390 | } |
||
| 391 | |||
| 392 | return $this; |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Is record is solid state? |
||
| 397 | * |
||
| 398 | * @see solidState() |
||
| 399 | * @return bool |
||
| 400 | */ |
||
| 401 | public function isSolid() |
||
| 402 | { |
||
| 403 | return $this->solidState; |
||
| 404 | } |
||
| 405 | |||
| 406 | /** |
||
| 407 | * {@inheritdoc} |
||
| 408 | */ |
||
| 409 | public function recordRole() |
||
| 410 | { |
||
| 411 | return $this->ormSchema[ORM::M_ROLE_NAME]; |
||
| 412 | } |
||
| 413 | |||
| 414 | /** |
||
| 415 | * {@inheritdoc} |
||
| 416 | */ |
||
| 417 | public function primaryKey() |
||
| 418 | { |
||
| 419 | return isset($this->fields[$this->ormSchema[ORM::M_PRIMARY_KEY]]) |
||
| 420 | ? $this->fields[$this->ormSchema[ORM::M_PRIMARY_KEY]] |
||
| 421 | : null; |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * {@inheritdoc} |
||
| 426 | */ |
||
| 427 | public function isLoaded() |
||
| 428 | { |
||
| 429 | return (bool)$this->loaded && !$this->isDeleted(); |
||
| 430 | } |
||
| 431 | |||
| 432 | /** |
||
| 433 | * {@inheritdoc} |
||
| 434 | */ |
||
| 435 | public function isDeleted() |
||
| 436 | { |
||
| 437 | return $this->loaded === self::DELETED; |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Pivot data associated with record instance, populated only in cases when record loaded using |
||
| 442 | * Many-to-Many relation. |
||
| 443 | * |
||
| 444 | * @return array |
||
| 445 | */ |
||
| 446 | public function getPivot() |
||
| 447 | { |
||
| 448 | return $this->pivotData; |
||
| 449 | } |
||
| 450 | |||
| 451 | /** |
||
| 452 | * {@inheritdoc} |
||
| 453 | * |
||
| 454 | * @see $fillable |
||
| 455 | * @see $secured |
||
| 456 | * @see isFillable() |
||
| 457 | * @param array|\Traversable $fields |
||
| 458 | * @param bool $all Fill all fields including non fillable. |
||
| 459 | * @return $this |
||
| 460 | * @throws AccessorExceptionInterface |
||
| 461 | * @event setFields($fields) |
||
| 462 | */ |
||
| 463 | public function setFields($fields = [], $all = false) |
||
| 464 | { |
||
| 465 | parent::setFields($fields, $all); |
||
| 466 | |||
| 467 | foreach ($fields as $name => $nested) { |
||
| 468 | //We can fill data of embedded of relations (usually HAS ONE) |
||
| 469 | if ($this->isEmbedded($name)) { |
||
| 470 | //Getting relation instance |
||
| 471 | $relation = $this->relation($name); |
||
| 472 | |||
| 473 | //Getting related object |
||
| 474 | $related = $relation->getRelated(); |
||
| 475 | if ($related instanceof EntityInterface) { |
||
| 476 | $related->setFields($nested); |
||
| 477 | } |
||
| 478 | } |
||
| 479 | } |
||
| 480 | |||
| 481 | return $this; |
||
| 482 | } |
||
| 483 | |||
| 484 | /** |
||
| 485 | * {@inheritdoc} |
||
| 486 | * |
||
| 487 | * Must track field updates. In addition Records will not allow to set unknown field. |
||
| 488 | * |
||
| 489 | * @throws RecordException |
||
| 490 | */ |
||
| 491 | public function setField($name, $value, $filter = true) |
||
| 492 | { |
||
| 493 | if (!$this->hasField($name)) { |
||
| 494 | throw new RecordException("Undefined field '{$name}' in '" . static::class . "'."); |
||
| 495 | } |
||
| 496 | |||
| 497 | //Original values with no filters |
||
| 498 | $original = parent::getField($name, null, false); |
||
|
|
|||
| 499 | if ($value === null && in_array($name, $this->ormSchema[ORM::M_NULLABLE])) { |
||
| 500 | //We must bypass setters and accessors when null value assigned to nullable column |
||
| 501 | $this->setField($name, null, false); |
||
| 502 | } else { |
||
| 503 | parent::setField($name, $value, $filter); |
||
| 504 | } |
||
| 505 | |||
| 506 | View Code Duplication | if (!array_key_exists($name, $this->updates)) { |
|
| 507 | $this->updates[$name] = $original instanceof AccessorInterface |
||
| 508 | ? $original->serializeData() |
||
| 509 | : $original; |
||
| 510 | } |
||
| 511 | } |
||
| 512 | |||
| 513 | /** |
||
| 514 | * {@inheritdoc} |
||
| 515 | * |
||
| 516 | * Record will skip filtration for nullable fields. |
||
| 517 | */ |
||
| 518 | public function getField($name, $default = null, $filter = true) |
||
| 519 | { |
||
| 520 | if (!$this) { |
||
| 521 | throw new RecordException("Undefined field '{$name}' in '" . static::class . "'."); |
||
| 522 | } |
||
| 523 | |||
| 524 | $value = $this->fields[$name]; |
||
| 525 | if ($value === null && in_array($name, $this->ormSchema[ORM::M_NULLABLE])) { |
||
| 526 | if (!isset($this->ormSchema[ORM::M_MUTATORS]['accessor'][$name])) { |
||
| 527 | //We can skip setters for null values, but not accessors |
||
| 528 | return $value; |
||
| 529 | } |
||
| 530 | } |
||
| 531 | |||
| 532 | return parent::getField($name, $default, $filter); |
||
| 533 | } |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Get or create record relation by it's name and pre-loaded (optional) set of data. |
||
| 537 | * |
||
| 538 | * @param string $name |
||
| 539 | * @param mixed $data |
||
| 540 | * @param bool $loaded |
||
| 541 | * @return RelationInterface |
||
| 542 | * @throws RelationException |
||
| 543 | * @throws RecordException |
||
| 544 | */ |
||
| 545 | public function relation($name, $data = null, $loaded = false) |
||
| 574 | |||
| 575 | /** |
||
| 576 | * {@inheritdoc} |
||
| 577 | * |
||
| 578 | * @param string $field Specific field name to check for updates. |
||
| 579 | */ |
||
| 580 | public function hasUpdates($field = null) |
||
| 607 | |||
| 608 | /** |
||
| 609 | * {@inheritdoc} |
||
| 610 | */ |
||
| 611 | public function flushUpdates() |
||
| 621 | |||
| 622 | /** |
||
| 623 | * {@inheritdoc} |
||
| 624 | */ |
||
| 625 | public function isValid() |
||
| 631 | |||
| 632 | /** |
||
| 633 | * {@inheritdoc} |
||
| 634 | */ |
||
| 635 | public function getErrors($reset = false) |
||
| 639 | |||
| 640 | /** |
||
| 641 | * {@inheritdoc} |
||
| 642 | */ |
||
| 643 | public function __isset($name) |
||
| 651 | |||
| 652 | /** |
||
| 653 | * {@inheritdoc} |
||
| 654 | * |
||
| 655 | * @throws RecordException |
||
| 656 | */ |
||
| 657 | public function __unset($offset) |
||
| 661 | |||
| 662 | /** |
||
| 663 | * {@inheritdoc} |
||
| 664 | * |
||
| 665 | * @see relation() |
||
| 666 | */ |
||
| 667 | public function __get($offset) |
||
| 676 | |||
| 677 | /** |
||
| 678 | * {@inheritdoc} |
||
| 679 | * |
||
| 680 | * @see relation() |
||
| 681 | */ |
||
| 682 | public function __set($offset, $value) |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Direct access to relation by it's name. |
||
| 696 | * |
||
| 697 | * @see relation() |
||
| 698 | * @param string $method |
||
| 699 | * @param array $arguments |
||
| 700 | * @return RelationInterface|mixed|AccessorInterface |
||
| 701 | */ |
||
| 702 | public function __call($method, array $arguments) |
||
| 711 | |||
| 712 | /** |
||
| 713 | * @return Object |
||
| 714 | */ |
||
| 715 | public function __debugInfo() |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Get associated Database\Table instance. |
||
| 733 | * |
||
| 734 | * @see save() |
||
| 735 | * @see delete() |
||
| 736 | * @return Table |
||
| 737 | */ |
||
| 738 | protected function sourceTable() |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Get WHERE array to be used to perform record data update or deletion. Usually will include |
||
| 747 | * record primary key. |
||
| 748 | * |
||
| 749 | * @return array |
||
| 750 | */ |
||
| 751 | protected function stateCriteria() |
||
| 760 | |||
| 761 | /** |
||
| 762 | * {@inheritdoc} |
||
| 763 | */ |
||
| 764 | protected function container() |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Create set of fields to be sent to UPDATE statement. |
||
| 775 | * |
||
| 776 | * @see save() |
||
| 777 | * @return array |
||
| 778 | */ |
||
| 779 | protected function compileUpdates() |
||
| 811 | |||
| 812 | /** |
||
| 813 | * {@inheritdoc} |
||
| 814 | * |
||
| 815 | * Will validate every loaded and embedded relation. |
||
| 816 | */ |
||
| 817 | View Code Duplication | protected function validate($reset = false) |
|
| 841 | |||
| 842 | /** |
||
| 843 | * {@inheritdoc} |
||
| 844 | * |
||
| 845 | * @see Component::staticContainer() |
||
| 846 | * @param array $fields Record fields to set, will be passed thought filters. |
||
| 847 | * @param ORM $orm ORM component, global container will be called if not instance provided. |
||
| 848 | * @event created() |
||
| 849 | */ |
||
| 850 | View Code Duplication | public static function create($fields = [], ORM $orm = null) |
|
| 862 | |||
| 863 | /** |
||
| 864 | * Change record loaded state. |
||
| 865 | * |
||
| 866 | * @param bool|mixed $loader |
||
| 867 | * @return $this |
||
| 868 | */ |
||
| 869 | protected function loadedState($loader) |
||
| 875 | |||
| 876 | /** |
||
| 877 | * Related and cached ORM schema. |
||
| 878 | * |
||
| 879 | * @return array |
||
| 880 | */ |
||
| 881 | protected function ormSchema() |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Check if relation is embedded. |
||
| 888 | * |
||
| 889 | * @param string $relation |
||
| 890 | * @return bool |
||
| 891 | */ |
||
| 892 | protected function isEmbedded($relation) |
||
| 898 | |||
| 899 | /** |
||
| 900 | * Full structure update. |
||
| 901 | * |
||
| 902 | * @return array |
||
| 903 | */ |
||
| 904 | private function solidUpdate() |
||
| 922 | |||
| 923 | /** |
||
| 924 | * Validate embedded relations. |
||
| 925 | * |
||
| 926 | * @param bool $reset |
||
| 927 | */ |
||
| 928 | private function validateRelations($reset) |
||
| 941 | } |
||
| 942 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.