diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c61bb9f..1d148c4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,10 +12,10 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['5.6', '7.4'] + php-version: ['7.2', '7.4', '8.0'] prefer-lowest: [''] include: - - php-version: '5.6' + - php-version: '7.2' prefer-lowest: 'prefer-lowest' steps: @@ -44,7 +44,7 @@ jobs: - name: Composer install --no-progress --prefer-dist --optimize-autoloader run: | composer --version - composer require --dev phpunit/phpunit:"^5.7.27|^6.5.12|^7.0|^8.5|^9.5" + composer require --dev phpunit/phpunit:"^8.5|^9.5" if ${{ matrix.prefer-lowest == 'prefer-lowest' }} then composer update --prefer-lowest --prefer-stable diff --git a/README.md b/README.md index 6ffe3c5..48581af 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MediaEmbed [![CI](https://github.com/dereuromark/media-embed/workflows/CI/badge.svg)](https://github.com/dereuromark/media-embed/actions?query=workflow%3ACI+branch%3Amaster) -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg)](https://php.net/) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.2-8892BF.svg)](https://php.net/) [![License](https://poser.pugx.org/dereuromark/media-embed/license.svg)](https://packagist.org/packages/dereuromark/media-embed) [![Total Downloads](https://poser.pugx.org/dereuromark/media-embed/d/total.svg)](https://packagist.org/packages/dereuromark/media-embed) [![Coding Standards](https://img.shields.io/badge/cs-PSR--2--R-yellow.svg)](https://github.com/php-fig-rectified/fig-rectified-standards) @@ -25,7 +25,7 @@ https://sandbox.dereuromark.de/sandbox/media-embed ## Requirements -- PHP 5.6+ +- PHP 7.2+ since 0.6 - Composer - [jbroadway/urlify](https://github.com/jbroadway/urlify) for slugging diff --git a/composer.json b/composer.json index 934d960..1ca01bd 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ } ], "require": { - "php": ">=5.6", + "php": ">=7.2", "jbroadway/urlify": "^1.0.0" }, "require-dev":{ "sebastian/diff": "@stable", - "fig-r/psr2r-sniffer": "^0.6" + "fig-r/psr2r-sniffer": "dev-master" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 520ddeb..69de33f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,26 +1,29 @@ - + + tests/ - - + + src/ - - src/Docs/ - - - + + + src/Docs/ + + + + + + + - - - - - + - diff --git a/src/Docs/Generator.php b/src/Docs/Generator.php index 7307667..79c1da2 100644 --- a/src/Docs/Generator.php +++ b/src/Docs/Generator.php @@ -11,8 +11,8 @@ class Generator { use DiffTrait; - const CODE_SUCCESS = 0; - const CODE_ERROR = 1; + public const CODE_SUCCESS = 0; + public const CODE_ERROR = 1; /** * @var bool diff --git a/src/MediaEmbed.php b/src/MediaEmbed.php index 7eb4d13..9e7d9a8 100644 --- a/src/MediaEmbed.php +++ b/src/MediaEmbed.php @@ -70,8 +70,10 @@ public function parseId($id, $host, $config = []) { if (!$res) { $stub = []; $Object = $this->object($stub, $config); + return $Object; } + //TODO return null; } @@ -117,6 +119,7 @@ public function parseUrl($url, $config = []) { $stub['match'] = $this->_match; $Object = $this->object($stub, $config + $this->config); + return $Object; } @@ -137,6 +140,7 @@ protected function _matchUrl($url, array $regexRules) { return $match; } } + return []; } @@ -162,6 +166,7 @@ protected function _parseLink($url, $regex) { if (preg_match('~' . $regex . '~imu', $source, $match)) { $this->_match = $match; + return true; } @@ -183,6 +188,7 @@ public function setHosts(array $stubs, $reset = false) { $slug = $this->_slug($stub['name']); $this->_hosts[$slug] = $stub; } + return $this; } @@ -199,6 +205,7 @@ public function getHosts($whitelist = []) { } $res[$slug] = $host; } + return $res; } @@ -216,6 +223,7 @@ public function getHost($alias) { if (empty($this->_hosts[$alias])) { return null; } + return $this->_hosts[$alias]; } @@ -246,6 +254,7 @@ public function object($stub, array $config = []) { if (!isset($stub['slug']) && !empty($stub['name'])) { $stub['slug'] = $this->_slug($stub['name']); } + return new MediaObject($stub, $config); } diff --git a/src/Object/MediaObject.php b/src/Object/MediaObject.php index f94f113..8e16201 100644 --- a/src/Object/MediaObject.php +++ b/src/Object/MediaObject.php @@ -115,6 +115,7 @@ public function stub($property = null, $value = null) { if (!empty($property) && !empty($value)) { $this->_stub[$property] = $value; } + return $this; } @@ -138,6 +139,7 @@ public function id() { for ($i = 1; $i <= $count; $i++) { $id = str_ireplace('$' . $i, $res[$i - 1], $id); } + return $id; } @@ -167,6 +169,7 @@ public function name() { for ($i = 1; $i <= $count; $i++) { $name = str_ireplace('$' . $i, $res[$i - 1], $name); } + return $name; } @@ -207,6 +210,7 @@ public function icon() { if ($file === false) { return null; } + // TODO: transform into 16x16 png return $file; } @@ -214,7 +218,7 @@ public function icon() { /** * @param string $location Absolute path with trailing slash * @param string|null $icon Icon data - * @return string|null $filename + * @return string|null Filename */ public function saveIcon($location, $icon = null) { if ($icon === null) { @@ -231,6 +235,7 @@ public function saveIcon($location, $icon = null) { if (!file_put_contents($file, $icon)) { return null; } + return $filename; } @@ -264,13 +269,14 @@ public function setParam($param, $value = null) { $this->_objectParams[$param] = $value; } } + return $this; } /** * Override a default object attribute value * - * @param mixed $param The name of the attribute to be set + * @param mixed $param The name of the attribute to be set * or an array of multiple attribs to be set * @param string|int|null $value (optional) the value to set the param to * if only one param is being set @@ -296,6 +302,7 @@ public function setAttribute($param, $value = null) { $this->_objectAttributes[$param] = $value; } } + return $this; } @@ -310,6 +317,7 @@ public function setHeight($height, $adjustWidth = false) { if ($adjustWidth && is_numeric($height)) { $this->_adjustDimensions('width', 'height', $height); } + return $this->setAttribute('height', $height); } @@ -324,6 +332,7 @@ public function setWidth($width, $adjustHeight = false) { if ($adjustHeight && is_numeric($width)) { $this->_adjustDimensions('height', 'width', $width); } + return $this->setAttribute('width', $width); } @@ -359,6 +368,7 @@ public function getParams($key = null) { if (!isset($this->_iframeParams[$key])) { return null; } + return $this->_iframeParams[$key]; } @@ -368,6 +378,7 @@ public function getParams($key = null) { if (!isset($this->_objectParams[$key])) { return null; } + return $this->_objectParams[$key]; } @@ -385,6 +396,7 @@ public function getAttributes($key = null) { if (!isset($this->_iframeAttributes[$key])) { return null; } + return $this->_iframeAttributes[$key]; } @@ -394,6 +406,7 @@ public function getAttributes($key = null) { if (!isset($this->_objectAttributes[$key])) { return null; } + return $this->_objectAttributes[$key]; } @@ -406,6 +419,7 @@ public function getEmbedCode() { if (!empty($this->_stub['iframe-player']) && $this->config['prefer'] === 'iframe') { return $this->_buildIframe(); } + return $this->_buildObject(); } @@ -446,9 +460,11 @@ protected function prefers($type = null) { if (!empty($this->_stub['iframe-player']) && $this->config['prefer'] === 'iframe') { $prefers = 'iframe'; } + return $prefers; } $this->config['prefer'] = $type; + return $this; } @@ -474,6 +490,7 @@ protected function _getObjectSrc($type = 'embed-src') { $src = str_replace($placeholder, $replacement, $src); } } + return $src; } @@ -545,6 +562,7 @@ protected function _buildObject() { if (!$objectAttributes && !$objectParams) { return ''; } + return sprintf(' %s', $objectAttributes, $objectParams); } diff --git a/tests/MediaEmbedTest.php b/tests/MediaEmbedTest.php index 779168f..d954a1a 100644 --- a/tests/MediaEmbedTest.php +++ b/tests/MediaEmbedTest.php @@ -143,6 +143,7 @@ public function getUrls() { foreach ($this->_stubs as $k => $v) { $urls[] = [$k, $v]; } + return $urls; }