Skip to content

Commit

Permalink
Removed deprecated packages
Browse files Browse the repository at this point in the history
  • Loading branch information
balazscsaba committed Nov 5, 2021
1 parent 5d0a065 commit dd8c0f6
Show file tree
Hide file tree
Showing 22 changed files with 328 additions and 788 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
vendor
composer.lock
composer.lock
.phpunit.result.cache
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
}
],
"require": {
"php": ">=7.1",
"php": "^7.4 || ^8.0",
"ext-mbstring": "*",
"ext-json": "*",
"layershifter/tld-extract": "^2.0"
"utopia-php/domains": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
"phpunit/phpunit": "^9.5"
},
"scripts": {
"test": "vendor/bin/phpunit"
Expand Down
31 changes: 11 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Socially Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Socially Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
43 changes: 0 additions & 43 deletions src/HumanDirect/Socially/Factory.php

This file was deleted.

4 changes: 0 additions & 4 deletions src/HumanDirect/Socially/NormalizableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ interface NormalizableInterface
{
/**
* Normalize a URL.
*
* @param string $url
*
* @return string
*/
public function normalize(string $url): string;
}
61 changes: 7 additions & 54 deletions src/HumanDirect/Socially/Normalizer/DefaultNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,20 @@

namespace HumanDirect\Socially\Normalizer;

use HumanDirect\Socially\Factory;
use HumanDirect\Socially\Util;
use Utopia\Domains\Domain;

/**
* Class DefaultNormalizer.
*/
class DefaultNormalizer implements NormalizerInterface
{
/**
* @var bool
*/
protected $stripSubdomain = true;

/**
* @var bool
*/
protected $stripQueryStrings = true;

/**
* @var array
*/
protected $allowedQueryParams = [
'id'
];
protected bool $stripSubdomain = true;
protected bool $stripQueryStrings = true;
protected array $allowedQueryParams = ['id'];

/**
* Normalize a URL.
*
* @param string $url
*
* @return string
*/
public function normalize(string $url): string
{
Expand All @@ -43,9 +26,6 @@ public function normalize(string $url): string
return $this->afterNormalization($url);
}

/**
* {@inheritdoc}
*/
public function afterNormalization(string $url): string
{
if (true === $this->stripSubdomain) {
Expand All @@ -67,53 +47,26 @@ public function supports(string $platform): bool
return $this->getName() === Util::toCamelCase($platform);
}

/**
* @throws \ReflectionException
*
* @return string
*/
protected function getName(): string
{
$shortName = (new \ReflectionClass($this))->getShortName();

return substr($shortName, 0, -10);
}

/**
* @param string $url
*
* @return string
*/
protected function cleanUrl(string $url): string
{
return rtrim(Util::cleanUrl($url), '/');
}

/**
* @param string $url
*
* @throws \LayerShifter\TLDExtract\Exceptions\RuntimeException
*
* @return string
*/
private function cleanSubdomain(string $url): string
{
$tldExtractor = Factory::createTldExtractor();
$result = $tldExtractor->parse($url);
$subdomain = $result->getSubdomain();
$domain = new Domain(parse_url($url, PHP_URL_HOST));
$subdomain = $domain->getSub();

if (null === $subdomain) {
return $url;
}

return str_replace($subdomain . '.', '', $url);
return !empty($subdomain) ? str_replace($subdomain . '.', '', $url) : $url;
}

/**
* @param string $url
*
* @return string
*/
private function cleanQueryString(string $url): string
{
// all query params and fragments have to be removed
Expand Down
8 changes: 5 additions & 3 deletions src/HumanDirect/Socially/Normalizer/FacebookNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class FacebookNormalizer extends DefaultNormalizer
public function afterNormalization(string $url): string
{
$url = parent::afterNormalization($url);
$url = str_replace('fb.com', 'facebook.com', $url);

$url = str_replace(['.com/sharer.php', '.com/sharer/sharer.php'], '.com', $url);
$url = str_replace(
['fb.com', '.com/sharer.php', '.com/sharer/sharer.php'],
['facebook.com', '.com', '.com'],
$url
);

return rtrim($url, '/');
}
Expand Down
5 changes: 1 addition & 4 deletions src/HumanDirect/Socially/Normalizer/GooglePlusNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
*/
class GooglePlusNormalizer extends DefaultNormalizer
{
/**
* @var bool
*/
protected $stripSubdomain = false;
protected bool $stripSubdomain = false;
}
5 changes: 0 additions & 5 deletions src/HumanDirect/Socially/Normalizer/NormalizerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,5 @@
*/
interface NormalizerInterface extends NormalizableInterface, SupportsNormalizerInterface
{
/**
* @param string $url
*
* @return string
*/
public function afterNormalization(string $url): string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
*/
class StackoverflowCareersNormalizer extends DefaultNormalizer
{
/**
* @var bool
*/
protected $stripSubdomain = false;
protected bool $stripSubdomain = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ interface SupportsNormalizerInterface
{
/**
* Does normalizer support platform?
*
* @param string $platform
*
* @return bool
*/
public function supports(string $platform): bool;
}
13 changes: 5 additions & 8 deletions src/HumanDirect/Socially/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace HumanDirect\Socially;

use FilesystemIterator;
use HumanDirect\Socially\Normalizer\DefaultNormalizer;
use HumanDirect\Socially\Normalizer\NormalizerInterface;

Expand All @@ -13,7 +14,7 @@ class Parser implements ParserInterface
/**
* @var NormalizerInterface[]
*/
private $normalizers;
private array $normalizers;

/**
* {@inheritdoc}
Expand All @@ -24,15 +25,15 @@ public function parse(string $url): ResultInterface
throw new NotSupportedException('Supplied URL is not a social media profile URL.');
}

return Result::createFromUrl($url);
return Result::create($url);
}

/**
* {@inheritdoc}
*/
public function normalize(string $url): string
{
if (null === $this->normalizers) {
if (!isset($this->normalizers)) {
$this->loadNormalizers();
}

Expand Down Expand Up @@ -89,7 +90,7 @@ private function loadNormalizers(): void
$normalizerNS = '\\HumanDirect\\Socially\\Normalizer\\';
$directory = new \RecursiveDirectoryIterator(
__DIR__ . '/Normalizer',
\RecursiveDirectoryIterator::SKIP_DOTS
FilesystemIterator::SKIP_DOTS
);
$files = new \RecursiveCallbackFilterIterator($directory, function ($current, $key, $iterator) use ($normalizerNS) {
$className = str_replace('.php', '', $current->getFilename());
Expand All @@ -112,10 +113,6 @@ private function loadNormalizers(): void

/**
* Get a normalizer for a specific platform or a default normalizer.
*
* @param string $platform
*
* @return NormalizerInterface
*/
private function getNormalizer(string $platform): NormalizerInterface
{
Expand Down
16 changes: 0 additions & 16 deletions src/HumanDirect/Socially/ParserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,12 @@ interface ParserInterface extends NormalizableInterface
/**
* Parse URL to parts.
*
* @param string $url
*
* @throws NotSupportedException
*
* @return ResultInterface
*/
public function parse(string $url): ResultInterface;

/**
* Returns true if the supplied URL is a valid social media profile URL.
*
* @param string $url
*
* @return bool
*/
public function isSocialMediaProfile(string $url): bool;

Expand All @@ -140,22 +132,14 @@ public function isSocialMediaProfile(string $url): bool;
*
* Returned string can be for eg. facebook, or stackoverflow.careers
*
* @param string $url
*
* @throws NotSupportedException
*
* @return string
*/
public function identifyPlatform(string $url): string;

/**
* Normalize a URL.
*
* @param string $url
*
* @throws NotSupportedException
*
* @return string
*/
public function normalize(string $url): string;
}
Loading

0 comments on commit dd8c0f6

Please sign in to comment.