for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace vfalies\tmdb\Abstracts;
abstract class Element
{
/**
* Get item poster
* @param string $size
* @return string
*/
public function getPoster(string $size = 'w185'): string
return $this->getImage('poster', $size);
}
* Get item backdrop
* @return string|null
public function getBackdrop(string $size = 'w780'): string
return $this->getImage('backdrop', $size);
* Get poster path
public function getPosterPath(): string
if (isset($this->data->poster_path))
return $this->data->poster_path;
data
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 '';
* Get backdrop
public function getBackdropPath(): string
if (isset($this->data->backdrop_path))
return $this->data->backdrop_path;
* Get image url from type and size
* @param string $type
* @throws \Exception
private function getImage(string $type, string $size): string
$path = $type . '_path';
if (isset($this->data->$path))
if (!isset($this->conf->images->base_url))
conf
throw new \Exception('base_url configuration not found');
$sizes = $type . '_sizes';
if (!in_array($size, $this->conf->images->$sizes))
throw new \Exception('Incorrect ' . $type . ' size : ' . $size);
return $this->conf->images->base_url . $size . $this->data->$path;
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: