Skip to content

Commit

Permalink
Merge pull request #1937 from acelaya-forks/feature/remove-functional
Browse files Browse the repository at this point in the history
Feature/remove functional
  • Loading branch information
acelaya authored Nov 30, 2023
2 parents a91a560 + 1854cc2 commit d3570da
Show file tree
Hide file tree
Showing 62 changed files with 448 additions and 267 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]
### Added
* *Nothing*

### Changed
* Remove dependency on functional-php library

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* *Nothing*


## [3.7.0] - 2023-11-25
### Added
* [#1798](https://github.com/shlinkio/shlink/issues/1798) Experimental support to send visits to an external Matomo instance.
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"laminas/laminas-servicemanager": "^3.21",
"laminas/laminas-stdlib": "^3.17",
"league/uri": "^6.8",
"lstrojny/functional-php": "^1.17",
"matomo/matomo-php-tracker": "^3.2",
"mezzio/mezzio": "^3.17",
"mezzio/mezzio-fastroute": "^3.10",
Expand All @@ -46,12 +45,12 @@
"php-middleware/request-id": "^4.1",
"pugx/shortid-php": "^1.1",
"ramsey/uuid": "^4.7",
"shlinkio/shlink-common": "^5.7",
"shlinkio/shlink-common": "dev-main#1f1b3b8 as 5.8",
"shlinkio/shlink-config": "^2.5",
"shlinkio/shlink-event-dispatcher": "^3.1",
"shlinkio/shlink-importer": "^5.2",
"shlinkio/shlink-installer": "^8.6",
"shlinkio/shlink-ip-geolocation": "^3.3",
"shlinkio/shlink-importer": "dev-main#4616c54 as 5.3",
"shlinkio/shlink-installer": "dev-develop#cb0eaea as 8.7",
"shlinkio/shlink-ip-geolocation": "dev-main#ea88ae8 as 3.4",
"shlinkio/shlink-json": "^1.1",
"spiral/roadrunner": "^2023.2",
"spiral/roadrunner-cli": "^2.5",
Expand Down Expand Up @@ -80,6 +79,9 @@
"symfony/var-dumper": "^6.3",
"veewee/composer-run-parallel": "^1.3"
},
"conflict": {
"symfony/var-exporter": ">=6.3.9,<=6.4.0"
},
"autoload": {
"psr-4": {
"Shlinkio\\Shlink\\CLI\\": "module/CLI/src",
Expand All @@ -88,6 +90,7 @@
},
"files": [
"config/constants.php",
"module/Core/functions/array-utils.php",
"module/Core/functions/functions.php"
]
},
Expand Down
4 changes: 2 additions & 2 deletions config/autoload/entity-manager.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Happyr\DoctrineSpecification\Repository\EntitySpecificationRepository;
use Shlinkio\Shlink\Core\Config\EnvVars;

use function Functional\contains;
use function Shlinkio\Shlink\Core\ArrayUtils\contains;

return (static function (): array {
$driver = EnvVars::DB_DRIVER->loadFromEnv();
$isMysqlCompatible = contains(['maria', 'mysql'], $driver);
$isMysqlCompatible = contains($driver, ['maria', 'mysql']);

$resolveDriver = static fn () => match ($driver) {
'postgres' => 'pdo_pgsql',
Expand Down
4 changes: 2 additions & 2 deletions config/test/test_config.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

use function file_exists;
use function Functional\contains;
use function Laminas\Stratigility\middleware;
use function Shlinkio\Shlink\Config\env;
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
use function sprintf;
use function sys_get_temp_dir;

Expand All @@ -41,7 +41,7 @@
$isCliTest = env('TEST_ENV') === 'cli';
$isE2eTest = $isApiTest || $isCliTest;
$coverageType = env('GENERATE_COVERAGE');
$generateCoverage = contains(['yes', 'pretty'], $coverageType);
$generateCoverage = contains($coverageType, ['yes', 'pretty']);

$coverage = null;
if ($isE2eTest && $generateCoverage) {
Expand Down
4 changes: 2 additions & 2 deletions data/migrations/Version20200105165647.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;

use function Functional\some;
use function Shlinkio\Shlink\Core\ArrayUtils\some;

final class Version20200105165647 extends AbstractMigration
{
Expand All @@ -25,7 +25,7 @@ public function preUp(Schema $schema): void
$visitLocations = $schema->getTable('visit_locations');
$this->skipIf(some(
self::COLUMNS,
fn (string $v, string $newColName) => $visitLocations->hasColumn($newColName),
fn (string $v, string|int $newColName) => $visitLocations->hasColumn((string) $newColName),
), 'New columns already exist');

foreach (self::COLUMNS as $columnName) {
Expand Down
19 changes: 13 additions & 6 deletions data/migrations/Version20200106215144.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;

use function Functional\none;

final class Version20200106215144 extends AbstractMigration
{
private const COLUMNS = ['latitude', 'longitude'];
Expand All @@ -22,16 +21,24 @@ final class Version20200106215144 extends AbstractMigration
public function up(Schema $schema): void
{
$visitLocations = $schema->getTable('visit_locations');
$this->skipIf(none(
self::COLUMNS,
fn (string $oldColName) => $visitLocations->hasColumn($oldColName),
), 'Old columns do not exist');
$this->skipIf($this->oldColumnsDoNotExist($visitLocations), 'Old columns do not exist');

foreach (self::COLUMNS as $colName) {
$visitLocations->dropColumn($colName);
}
}

public function oldColumnsDoNotExist(Table $visitLocations): bool
{
foreach (self::COLUMNS as $oldColName) {
if ($visitLocations->hasColumn($oldColName)) {
return false;
}
}

return true;
}

/**
* @throws Exception
*/
Expand Down
13 changes: 5 additions & 8 deletions data/migrations/Version20200110182849.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

use function Functional\each;
use function Functional\partial_left;

final class Version20200110182849 extends AbstractMigration
{
private const DEFAULT_EMPTY_VALUE = '';
Expand All @@ -31,11 +28,11 @@ final class Version20200110182849 extends AbstractMigration

public function up(Schema $schema): void
{
each(
self::COLUMN_DEFAULTS_MAP,
fn (array $columns, string $tableName) =>
each($columns, partial_left([$this, 'setDefaultValueForColumnInTable'], $tableName)),
);
foreach (self::COLUMN_DEFAULTS_MAP as $tableName => $columns) {
foreach ($columns as $columnName) {
$this->setDefaultValueForColumnInTable($tableName, $columnName);
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ services:

shlink_swagger_ui:
container_name: shlink_swagger_ui
image: swaggerapi/swagger-ui:v5.9.1
image: swaggerapi/swagger-ui:v5.10.3
ports:
- "8005:8080"
volumes:
Expand Down
6 changes: 3 additions & 3 deletions module/CLI/src/Command/Api/ListKeysCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Console\Output\OutputInterface;

use function array_filter;
use function Functional\map;
use function array_map;
use function implode;
use function sprintf;

Expand Down Expand Up @@ -49,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
{
$enabledOnly = $input->getOption('enabled-only');

$rows = map($this->apiKeyService->listKeys($enabledOnly), function (ApiKey $apiKey) use ($enabledOnly) {
$rows = array_map(function (ApiKey $apiKey) use ($enabledOnly) {
$expiration = $apiKey->getExpirationDate();
$messagePattern = $this->determineMessagePattern($apiKey);

Expand All @@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
));

return $rowData;
});
}, $this->apiKeyService->listKeys($enabledOnly));

ShlinkTable::withRowSeparators($output)->render(array_filter([
'Key',
Expand Down
10 changes: 5 additions & 5 deletions module/CLI/src/Command/Db/CreateDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use Symfony\Component\Process\PhpExecutableFinder;
use Throwable;

use function Functional\contains;
use function Functional\map;
use function Functional\some;
use function array_map;
use function Shlinkio\Shlink\Core\ArrayUtils\contains;
use function Shlinkio\Shlink\Core\ArrayUtils\some;

class CreateDatabaseCommand extends AbstractDatabaseCommand
{
Expand Down Expand Up @@ -70,11 +70,11 @@ private function databaseTablesExist(): bool
{
$existingTables = $this->ensureDatabaseExistsAndGetTables();
$allMetadata = $this->em->getMetadataFactory()->getAllMetadata();
$shlinkTables = map($allMetadata, static fn (ClassMetadata $metadata) => $metadata->getTableName());
$shlinkTables = array_map(static fn (ClassMetadata $metadata) => $metadata->getTableName(), $allMetadata);

// If at least one of the shlink tables exist, we will consider the database exists somehow.
// Any other inconsistency will be taken care of by the migrations.
return some($shlinkTables, static fn (string $shlinkTable) => contains($existingTables, $shlinkTable));
return some($shlinkTables, static fn (string $shlinkTable) => contains($shlinkTable, $existingTables));
}

private function ensureDatabaseExistsAndGetTables(): array
Expand Down
12 changes: 6 additions & 6 deletions module/CLI/src/Command/Domain/DomainRedirectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function Functional\filter;
use function Functional\invoke;
use function array_filter;
use function array_map;
use function sprintf;
use function str_contains;

class DomainRedirectsCommand extends Command
{
public const NAME = 'domain:redirects';

public function __construct(private DomainServiceInterface $domainService)
public function __construct(private readonly DomainServiceInterface $domainService)
{
parent::__construct();
}
Expand Down Expand Up @@ -52,9 +52,9 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
$askNewDomain = static fn () => $io->ask('Domain authority for which you want to set specific redirects');

/** @var string[] $availableDomains */
$availableDomains = invoke(
filter($this->domainService->listDomains(), static fn (DomainItem $item) => ! $item->isDefault),
'toString',
$availableDomains = array_map(
static fn (DomainItem $item) => $item->toString(),
array_filter($this->domainService->listDomains(), static fn (DomainItem $item) => ! $item->isDefault),
);
if (empty($availableDomains)) {
$input->setArgument('domain', $askNewDomain());
Expand Down
8 changes: 4 additions & 4 deletions module/CLI/src/Command/Domain/ListDomainsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

use function Functional\map;
use function array_map;

class ListDomainsCommand extends Command
{
public const NAME = 'domain:list';

public function __construct(private DomainServiceInterface $domainService)
public function __construct(private readonly DomainServiceInterface $domainService)
{
parent::__construct();
}
Expand All @@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int

$table->render(
$showRedirects ? [...$commonFields, '"Not found" redirects'] : $commonFields,
map($domains, function (DomainItem $domain) use ($showRedirects) {
array_map(function (DomainItem $domain) use ($showRedirects) {
$commonValues = [$domain->toString(), $domain->isDefault ? 'Yes' : 'No'];

return $showRedirects
Expand All @@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
$this->notFoundRedirectsToString($domain->notFoundRedirectConfig),
]
: $commonValues;
}),
}, $domains),
);

return ExitCode::EXIT_SUCCESS;
Expand Down
9 changes: 4 additions & 5 deletions module/CLI/src/Command/ShortUrl/CreateShortUrlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
use Symfony\Component\Console\Style\SymfonyStyle;

use function array_map;
use function array_unique;
use function explode;
use function Functional\curry;
use function Functional\flatten;
use function Functional\unique;
use function Shlinkio\Shlink\Core\ArrayUtils\flatten;
use function sprintf;

class CreateShortUrlCommand extends Command
Expand Down Expand Up @@ -144,8 +143,8 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
return ExitCode::EXIT_FAILURE;
}

$explodeWithComma = curry(explode(...))(',');
$tags = unique(flatten(array_map($explodeWithComma, $input->getOption('tags'))));
$explodeWithComma = static fn (string $tag) => explode(',', $tag);
$tags = array_unique(flatten(array_map($explodeWithComma, $input->getOption('tags'))));
$customSlug = $input->getOption('custom-slug');
$maxVisits = $input->getOption('max-visits');
$shortCodeLength = $input->getOption('short-code-length') ?? $this->options->defaultShortCodesLength;
Expand Down
8 changes: 4 additions & 4 deletions module/CLI/src/Command/ShortUrl/ListShortUrlsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
use Symfony\Component\Console\Style\SymfonyStyle;

use function array_keys;
use function array_map;
use function array_pad;
use function explode;
use function Functional\map;
use function implode;
use function sprintf;

Expand Down Expand Up @@ -184,10 +184,10 @@ private function renderPage(
): Paginator {
$shortUrls = $this->shortUrlService->listShortUrls($params);

$rows = map($shortUrls, function (ShortUrl $shortUrl) use ($columnsMap) {
$rows = array_map(function (ShortUrl $shortUrl) use ($columnsMap) {
$rawShortUrl = $this->transformer->transform($shortUrl);
return map($columnsMap, fn (callable $call) => $call($rawShortUrl, $shortUrl));
});
return array_map(fn (callable $call) => $call($rawShortUrl, $shortUrl), $columnsMap);
}, [...$shortUrls]);

ShlinkTable::default($output)->render(
array_keys($columnsMap),
Expand Down
8 changes: 4 additions & 4 deletions module/CLI/src/Command/Tag/ListTagsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use function Functional\map;
use function array_map;

class ListTagsCommand extends Command
{
public const NAME = 'tag:list';

public function __construct(private TagServiceInterface $tagService)
public function __construct(private readonly TagServiceInterface $tagService)
{
parent::__construct();
}
Expand All @@ -44,9 +44,9 @@ private function getTagsRows(): array
return [['No tags found', '-', '-']];
}

return map(
$tags,
return array_map(
static fn (TagInfo $tagInfo) => [$tagInfo->tag, $tagInfo->shortUrlsCount, $tagInfo->visitsSummary->total],
[...$tags],
);
}
}
Loading

0 comments on commit d3570da

Please sign in to comment.