Skip to content

Commit

Permalink
phpstan.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 22, 2018
1 parent d8ba6ba commit 3524b55
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@
*.mo binary
*.pdf binary
*.phar binary

# Remove files for archives generated using `git archive`
phpunit.xml.dist export-ignore
.travis.yml export-ignore
.gitignore export-ignore
.gitattributes export-ignore
.editorconfig export-ignore
tests/phpstan.neon
19 changes: 15 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,31 @@ php:
- 7.0
- 7.3

env:
global:
- DEFAULT=1

matrix:
fast_finish: true

include:
- php: 5.6
env: PREFER_LOWEST=1

- php: 7.2
env: PHPCS=1 DEFAULT=0

before_script:
- composer install --prefer-dist --no-interaction
- if [[ $PHPCS != 1 ]]; then composer require phpunit/phpunit:"^5.0|^6.0|^7.0"; fi
- if [[ $PREFER_LOWEST != 1 ]]; then composer install --prefer-source --no-interaction ; fi
- if [[ $PREFER_LOWEST == 1 ]]; then composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable ; fi

- if [[ $DEFAULT == 1 ]]; then composer require phpunit/phpunit:"^5.0|^6.0|^7.0"; fi

script:
- if [[ $PHPCS != 1 ]]; then vendor/bin/phpunit ; fi
- if [[ $PHPCS == 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --ignore=tests/test_files/ src/ tests/ ; fi
- if [[ $DEFAULT == 1 ]]; then vendor/bin/phpunit ; fi

- if [[ $CHECKS == 1 ]]; then composer require --dev phpstan/phpstan-shim:"^0.10" && composer phpstan; fi
- if [[ $CHECKS == 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --ignore=tests/test_files/ src/ tests/ ; fi

notifications:
email: false
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,6 @@ composer require dereuromark/media-embed
```
This will get the latest tagged version for you.

Or manually add the dependency to your `composer.json`:
```json
{
"require": {
"dereuromark/media-embed": "0.*"
}
}
```
and run:

```bash
composer install
```

## API Overview

### Parsing
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"jbroadway/urlify": "^1.0.0"
},
"require-dev":{
"fig-r/psr2r-sniffer": "dev-master"
"fig-r/psr2r-sniffer": "dev-master",
"phpstan/phpstan-shim": "^0.10.5"
},
"autoload": {
"psr-4": {
Expand All @@ -31,6 +32,7 @@
"test": "php phpunit.phar",
"test-coverage": "php phpunit.phar --log-junit tmp/coverage/unitreport.xml --coverage-html tmp/coverage --coverage-clover tmp/coverage/coverage.xml",
"test-setup": "[ ! -f phpunit.phar ] && wget https://phar.phpunit.de/phpunit.phar || true",
"phpstan": "phpstan analyse -c tests/phpstan.neon -l 5 src/",
"cs-check": "phpcs -v -p --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --extensions=php --ignore=tests/test_files/ src/ tests/",
"cs-fix": "phpcbf -v --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --extensions=php --ignore=tests/test_files/ src/ tests/"
}
Expand Down
6 changes: 1 addition & 5 deletions src/Data/stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@
[
'name' => 'CollegeHumor',
'website' => 'http://www.collegehumour.com',
'name' => 'CollegeHumor',
'url-match' => 'http://(?:www\.)?collegehumor\.com/video:([0-9]{1,12})',
'embed-src' => 'http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=$2',
'embed-width' => '480',
Expand Down Expand Up @@ -386,7 +385,6 @@
[
'name' => 'Dropshots',
'website' => 'http://www.dropshots.com',
'name' => 'dropshots.com',
'url-match' => '(http://media(?:[0-9]{0,2})\.dropshots\.com/photos(?:(?:/(?:[0-9]{1,10})){1,3})\.flv)',
'embed-src' => 'http://www.dropshots.com/dropshotsplayer.swf?url=$2',
'embed-width' => '480',
Expand Down Expand Up @@ -520,7 +518,6 @@
[
'name' => 'GameTube',
'website' => 'http://www.gametube.org',
'name' => 'Gametube.org',
'url-match' => 'http://(?:www\.)?gametube\.org/(?:\#/video/|htmlVideo\.jsp\?id=|miniPlayer\.swf\?vidId=)([A-z0-9=_-]{28})',
'embed-src' => 'http://www.gametube.org/miniPlayer.swf?vidId=$2',
'embed-width' => '425',
Expand Down Expand Up @@ -1224,7 +1221,6 @@
[
'name' => 'Tu',
'website' => 'http://www.tu.tv',
'name' => 'Tu.tv',
'url-match' => '(http://tu\.tv/tutvweb\.swf\?xtp=(?:[0-9]{1,10}))',
'embed-src' => '$2',
'embed-width' => '425',
Expand Down Expand Up @@ -1510,7 +1506,7 @@
'embed-height' => '320',
'flashvars' => 'config=http://www.mehr-schbass.de/videos/xml-config.php?id=$2-embed',
'id' => '$2',
'name' => '$3',
//'name' => '$3',
],
];

Expand Down
13 changes: 9 additions & 4 deletions src/MediaEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ protected function _matchUrl($url, array $regexRules) {
protected function _parseLink($url, $regex) {
$context = stream_context_create(
['http' => ['header' => 'Connection: close']]);
$source = preg_replace('/[^(\x20-\x7F)]*/', '', file_get_contents($url, 0, $context));
$content = file_get_contents($url, false, $context);
if (!$content) {
return false;
}

$source = preg_replace('/[^(\x20-\x7F)]*/', '', $content);

if (preg_match('~' . $regex . '~imu', $source, $match)) {
$this->_match = $match;
Expand Down Expand Up @@ -172,7 +177,7 @@ public function setHosts(array $stubs, $reset = false) {

/**
* @param array $whitelist (alias/keys)
* @return array hostInfos or false on failure
* @return array Host info
*/
public function getHosts($whitelist = []) {
if ($whitelist) {
Expand All @@ -190,14 +195,14 @@ public function getHosts($whitelist = []) {

/**
* @param string $alias
* @return array hostInfos or false on failure
* @return array|null Host info or null on failure
*/
public function getHost($alias) {
if (!$this->_hosts) {
$this->_hosts = $this->getHosts();
}
if (empty($this->_hosts[$alias])) {
return false;
return null;
}
return $this->_hosts[$alias];
}
Expand Down
26 changes: 9 additions & 17 deletions src/Object/MediaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace MediaEmbed\Object;

use MediaEmbed\Object\ObjectInterface;

/**
* A generic object - for now.
*
Expand Down Expand Up @@ -55,7 +53,7 @@ class MediaObject implements ObjectInterface {
* @param array $config
*/
public function __construct(array $stub, array $config) {
$this->config = $config += $this->config;
$this->config = $config + $this->config;

$stubDefaults = [
'id' => '',
Expand Down Expand Up @@ -184,7 +182,7 @@ public function website() {
/**
* Returns a png img
*
* @return resource|null Resource or null if not available
* @return string|null Resource content or null if not available
*/
public function icon() {
$url = $this->_stub['website'];
Expand All @@ -201,7 +199,7 @@ public function icon() {
$context = stream_context_create(
['http' => ['header' => 'Connection: close']]);
// E.g. http://www.google.com/s2/favicons?domain=xyz.com
$file = file_get_contents($icon, 0, $context);
$file = file_get_contents($icon, false, $context);
if ($file === false) {
return null;
}
Expand All @@ -210,23 +208,19 @@ public function icon() {
}

/**
* @param string|null $location Absolute path with trailing slash
* @param string $location Absolute path with trailing slash
* @param string|null $icon Icon data
* @return string|null $filename
*/
public function saveIcon($location = null, $icon = null) {
public function saveIcon($location, $icon = null) {
if ($icon === null) {
$icon = $this->icon();
}
if (!$icon) {
return null;
}
if (!$location) {
$location = IMAGES . 'content' . DS . 'video_types';
if (!is_dir($location)) {
mkdir($location, 0755, true);
}
$location .= DS;
return null;
}
$filename = $this->slug() . '.png';
$file = $location . $filename;
Expand Down Expand Up @@ -274,7 +268,7 @@ public function setParam($param, $value = null) {
*
* @param mixed $param The name of the attribute to be set
* or an array of multiple attribs to be set
* @param string|null $value (optional) the value to set the param to
* @param string|int|null $value (optional) the value to set the param to
* if only one param is being set
* @return $this
*/
Expand Down Expand Up @@ -351,7 +345,7 @@ protected function _adjustDimensions($type, $fromType, $fromLength) {
* Return object params about the video metadata
*
* @param string|null $key
* @return array|string - object params
* @return array|string|null Object params
*/
public function getParams($key = null) {
if (!empty($this->_stub['iframe-player']) && $this->config['prefer'] === 'iframe') {
Expand All @@ -377,7 +371,7 @@ public function getParams($key = null) {
* Return object attribute
*
* @param string|null $key
* @return array - object attribute
* @return mixed Object attribute
*/
public function getAttributes($key = null) {
if (!empty($this->_stub['iframe-player']) && $this->config['prefer'] === 'iframe') {
Expand Down Expand Up @@ -455,8 +449,6 @@ protected function _getObjectSrc($type = 'embed-src') {
}

/**
* VideoLib::getImageSrc()
*
* @return string|null
*/
public function getImageSrc() {
Expand Down
1 change: 1 addition & 0 deletions tests/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parameters:

0 comments on commit 3524b55

Please sign in to comment.