Edit File by line
/home/barbar84/www/wp-conte.../plugins/wordpres.../src/presenta...
File: abstract-presentation.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Presentations;
[2] Fix | Delete
[3] Fix | Delete
use Exception;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* The abstract presentation class.
[7] Fix | Delete
*/
[8] Fix | Delete
class Abstract_Presentation {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* The model.
[12] Fix | Delete
*
[13] Fix | Delete
* @var mixed
[14] Fix | Delete
*/
[15] Fix | Delete
public $model;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Whether or not there is a presentation prototype.
[19] Fix | Delete
*
[20] Fix | Delete
* @var bool
[21] Fix | Delete
*/
[22] Fix | Delete
private $is_prototype = true;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Creates a model presentation.
[26] Fix | Delete
*
[27] Fix | Delete
* @param array $data The data that this is a presentation of.
[28] Fix | Delete
*
[29] Fix | Delete
* @return static A model presentation.
[30] Fix | Delete
*
[31] Fix | Delete
* @throws Exception If attempting to create a model presentation from another model presentation.
[32] Fix | Delete
*/
[33] Fix | Delete
public function of( $data ) {
[34] Fix | Delete
if ( ! $this->is_prototype() ) {
[35] Fix | Delete
throw new Exception( 'Attempting to create a model presentation from another model presentation. Use the prototype presentation gained from DI instead.' );
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
// Clone self to allow stateful services that do benefit from DI.
[39] Fix | Delete
$presentation = clone $this;
[40] Fix | Delete
foreach ( $data as $key => $value ) {
[41] Fix | Delete
$presentation->{$key} = $value;
[42] Fix | Delete
}
[43] Fix | Delete
$presentation->is_prototype = false;
[44] Fix | Delete
return $presentation;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Magic getter for lazy loading of generate functions.
[49] Fix | Delete
*
[50] Fix | Delete
* @param string $name The property to get.
[51] Fix | Delete
*
[52] Fix | Delete
* @return mixed The value if it could be generated.
[53] Fix | Delete
*
[54] Fix | Delete
* @throws Exception If there is no generator for the property.
[55] Fix | Delete
*/
[56] Fix | Delete
public function __get( $name ) {
[57] Fix | Delete
if ( $this->is_prototype() ) {
[58] Fix | Delete
throw new Exception( 'Attempting property access on prototype presentation. Use Presentation::of( $data ) to get a model presentation.' );
[59] Fix | Delete
}
[60] Fix | Delete
$generator = "generate_$name";
[61] Fix | Delete
if ( \method_exists( $this, $generator ) ) {
[62] Fix | Delete
$this->{$name} = $this->$generator();
[63] Fix | Delete
return $this->{$name};
[64] Fix | Delete
}
[65] Fix | Delete
throw new Exception( "Property $name has no generator. Expected function $generator." );
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Magic isset for ensuring methods that have a generator are recognised.
[70] Fix | Delete
*
[71] Fix | Delete
* @codeCoverageIgnore Wrapper method.
[72] Fix | Delete
*
[73] Fix | Delete
* @param string $name The property to get.
[74] Fix | Delete
*
[75] Fix | Delete
* @return bool Whether or not there is a generator for the requested property.
[76] Fix | Delete
*/
[77] Fix | Delete
public function __isset( $name ) {
[78] Fix | Delete
return \method_exists( $this, "generate_$name" );
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Returns `true` if this class is a prototype.
[83] Fix | Delete
*
[84] Fix | Delete
* @return bool If this class is a prototype or not.
[85] Fix | Delete
*
[86] Fix | Delete
* @codeCoverageIgnore Wrapper method.
[87] Fix | Delete
*/
[88] Fix | Delete
protected function is_prototype() {
[89] Fix | Delete
return $this->is_prototype;
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function