Skip to content

Commit

Permalink
PHP 5.6 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcBrillault committed Jul 16, 2018
1 parent fff451b commit 9ababc8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/Classes/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ abstract class Video extends EmbedRoot implements VideoInterface
/**
* @param int $width
*/
public function setWidth(int $width)
public function setWidth($width)
{
$this->width = $width;
}

/**
* @return int
*/
public function getWidth(): int
public function getWidth()
{
if ($this->width) {
return $this->width;
Expand All @@ -51,15 +51,15 @@ public function getWidth(): int
/**
* @param int $height
*/
public function setHeight(int $height)
public function setHeight($height)
{
$this->height = $height;
}

/**
* @return int
*/
public function getHeight(): int
public function getHeight()
{
if ($this->height) {
return $this->height;
Expand All @@ -68,15 +68,15 @@ public function getHeight(): int
return round($this->getWidth() / $this->getRatio());
}

public function setRatio(float $ratio)
public function setRatio($ratio)
{
$this->ratio = $ratio;
}

/**
* @return float
*/
public function getRatio(): float
public function getRatio()
{
return $this->ratio ?: getenv('EMBED_RATIO') ?: self::DEFAULT_RATIO;
}
Expand Down
19 changes: 13 additions & 6 deletions src/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,30 @@ class Embed
*/
private $regexpCache;

public function __construct(string $url)
/**
* Embed constructor.
*
* @param string $url
*/
public function __construct($url = '')
{
$this->setUrl($url);
if ($url) {
$this->setUrl($url);
}
}

/**
* @param string $url
*/
public function setUrl(string $url)
public function setUrl($url)
{
$this->url = $url;
}

/**
* @return string
*/
public function getUrl(): string
public function getUrl()
{
return $this->url;
}
Expand All @@ -41,7 +48,7 @@ public function getUrl(): string
* @return string
* @throws \Embryo\Embed\Exceptions\EmbedException
*/
public function getEmbeddedCode(): string
public function getEmbeddedCode()
{
foreach ($this->getRegexpCache() as $regexp => $className) {
if (preg_match($regexp, $this->url, $matches)) {
Expand All @@ -59,7 +66,7 @@ public function getEmbeddedCode(): string
* @param string $class
* @return \Embryo\Embed\EmbedRoot
*/
private function getClass(string $class): EmbedRoot
private function getClass($class)
{
return new $class();
}
Expand Down
12 changes: 6 additions & 6 deletions src/EmbedRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getRegexp()
/**
* @param string $id
*/
public function setId(string $id)
public function setId($id)
{
$this->id = $id;
}
Expand Down Expand Up @@ -72,7 +72,7 @@ protected function setEmbedCode()
/**
* @return string
*/
public function getEmbedCode(): string
public function getEmbedCode()
{
if (!$this->embedCode) {
$this->setEmbedCode();
Expand All @@ -85,7 +85,7 @@ public function getEmbedCode(): string
* @param string $key
* @return bool
*/
private function isInTemplate(string $key): bool
private function isInTemplate($key)
{
return strpos($this->template, $this->transformToTemplateKey($key)) !== false;
}
Expand All @@ -94,7 +94,7 @@ private function isInTemplate(string $key): bool
* @param string $key
* @return string
*/
private function transformToTemplateKey(string $key): string
private function transformToTemplateKey($key)
{
return sprintf('{%s}', strtoupper($key));
}
Expand All @@ -103,15 +103,15 @@ private function transformToTemplateKey(string $key): string
* @param string $key
* @return string
*/
private function getMethodNameFromKey(string $key): string
private function getMethodNameFromKey($key)
{
return 'get' . ucfirst($key);
}

/**
* @return array[string]
*/
private function getTemplateKeys(): array
private function getTemplateKeys()
{
preg_match_all('#\{([A-Z]+)\}#', $this->template, $matches);

Expand Down
10 changes: 5 additions & 5 deletions src/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Installer
const CACHE_FILENAME = 'regexpCache.json';
const DIR_NAME = '/classes';

private function setRegexpList(): void
private function setRegexpList()
{
$paths = $this->getFilePaths();
foreach ($paths as $path) {
Expand Down Expand Up @@ -49,7 +49,7 @@ private function getRegexpList()
* @param array $paths
* @return array
*/
private function getFilePaths(string $dirName = '', array $paths = []): array
private function getFilePaths($dirName = '', array $paths = [])
{
$rootDirName = __DIR__ . self::DIR_NAME;
$dirName = $dirName ?: $rootDirName;
Expand All @@ -71,15 +71,15 @@ private function getFilePaths(string $dirName = '', array $paths = []): array
* @param string $regexp
* @param string $className
*/
private function addToRegexpList(string $regexp, string $className): void
private function addToRegexpList($regexp, $className)
{
$this->regexpList[$regexp] = $className;
}

/**
* @return bool
*/
public static function writeCacheFile(): bool
public static function writeCacheFile()
{
$installer = new self();
$installer->setRegexpList();
Expand All @@ -96,7 +96,7 @@ public static function writeCacheFile(): bool
/**
* @return string
*/
public static function getCacheFilePath(): string
public static function getCacheFilePath()
{
return __DIR__ . '/' . self::CACHE_FILENAME;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Interfaces/EmbedInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

interface EmbedInterface
{
public function getEmbedCode(): string;
/**
* @return string
*/
public function getEmbedCode();
}
30 changes: 27 additions & 3 deletions src/Interfaces/VideoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,33 @@

interface VideoInterface
{
public function setWidth(int $width);
/**
* @param int $width
*/
public function setWidth($width);

public function setHeight(int $height);
/**
* @return int
*/
public function getWidth();

public function setRatio(float $ratio);
/**
* @param int $height
*/
public function setHeight($height);

/**
* @return int
*/
public function getHeight();

/**
* @param float $ratio
*/
public function setRatio($ratio);

/**
* @return float
*/
public function getRatio();
}

0 comments on commit 9ababc8

Please sign in to comment.