Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PHP8.1 #76

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: run-tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, json
coverage: none

- name: Install plantuml & graphviz
run: sudo apt-get install -y plantuml graphviz

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: |
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: make test
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ os:
dist: "bionic"

php:
- "7.4"
- "7.3"
- "7.2"
- "8.1"

install:
- "mkdir -p build/logs"
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.3-cli
FROM php:8.1-cli
RUN mkdir -p /usr/share/man/man1 \
&& apt-get update && apt-get install -y \
default-jdk \
Expand All @@ -7,8 +7,11 @@ RUN mkdir -p /usr/share/man/man1 \
&& apt-get install -y \
graphviz \
plantuml

COPY . /dephpend
WORKDIR /dephpend

RUN curl https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer | php -- --quiet \
&& php -n composer.phar install
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are at the place, what do you think, if we replace the installer part with e.G.:

COPY --from=composer:2.4.4 /usr/bin/composer /usr/bin/composer

ENTRYPOINT [ "php", "-n", "-d memory_limit=-1", "./bin/dephpend" ]

ENTRYPOINT [ "php", "-n", "-d", "memory_limit=-1", "./bin/dephpend" ]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ cov:

s: style
style:
@$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --level=psr2 --verbose src
@$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --level=psr2 --verbose tests
@$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --rules=@PSR12 --verbose src
@$(PHP_NO_INI) vendor/bin/php-cs-fixer fix --rules=@PSR12 --verbose tests

phar:
@php composer.phar update --no-dev
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
"homepage": "https://dephpend.com",
"bin": ["bin/dephpend", "bin/php-trace"],
"require": {
"php": "^7.2",
"php": "^8.1",
"nikic/php-parser": "^4.0",
"symfony/console": "^4 || ^5",
"symfony/event-dispatcher": "^4 || ^5"
"symfony/console": "^6",
"symfony/event-dispatcher": "^6"
},
"suggest": {
"ext-json": "*",
"ext-mbstring": "*",
"ext-tokenizer": "*"
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.3",
"friendsofphp/php-cs-fixer": "^2.12"
"mikey179/vfsstream": "^1.6.11",
"phpunit/phpunit": "^9.5.24",
"squizlabs/php_codesniffer": "^3.7",
"friendsofphp/php-cs-fixer": "^3.11"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
forceCoversAnnotation="true"
colors="true"
verbose="true">
<testsuite name="tests">
Expand Down
5 changes: 4 additions & 1 deletion src/Analyser/DependencyInspectionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function beforeTraverse(array $nodes)
/**
* @return DependencyMap
*/
public function dependencies() : DependencyMap
public function dependencies(): DependencyMap
{
return $this->dependencies;
}
Expand All @@ -173,6 +173,9 @@ private function setCurrentClass(ClassLikeNode $node)
} elseif ($node instanceof TraitNode) {
// @codeCoverageIgnoreEnd
$this->currentClass = $this->dependencyFactory->createTraitFromStringArray($node->namespacedName->parts);
} elseif ($node instanceof Node\Stmt\Enum_) {
// @codeCoverageIgnoreEnd
$this->currentClass = $this->dependencyFactory->createEnumFromStringArray($node->namespacedName->parts);
} else {
$this->currentClass = $node->isAbstract()
? $this->dependencyFactory->createAbstractClazzFromStringArray($node->namespacedName->parts)
Expand Down
16 changes: 8 additions & 8 deletions src/Analyser/Metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Metrics
*
* @return float Value from 0 (completely concrete) to 1 (completely abstract)
*/
public function abstractness(DependencyMap $map) : float
public function abstractness(DependencyMap $map): float
{
$abstractions = $this->abstractClassCount($map)
+ $this->interfaceCount($map)
Expand All @@ -30,28 +30,28 @@ public function abstractness(DependencyMap $map) : float
return $abstractions / $allClasses;
}

public function classCount(DependencyMap $map) : int
public function classCount(DependencyMap $map): int
{
return $this->countFilteredItems($map, function (Dependency $dependency) {
return $dependency instanceof Clazz;
});
}

public function abstractClassCount(DependencyMap $map) : int
public function abstractClassCount(DependencyMap $map): int
{
return $this->countFilteredItems($map, function (Dependency $dependency) {
return $dependency instanceof AbstractClazz;
});
}

public function interfaceCount(DependencyMap $map) : int
public function interfaceCount(DependencyMap $map): int
{
return $this->countFilteredItems($map, function (Dependency $dependency) {
return $dependency instanceof Interfaze;
});
}

public function traitCount(DependencyMap $map) : int
public function traitCount(DependencyMap $map): int
{
return $this->countFilteredItems($map, function (Dependency $dependency) {
return $dependency instanceof Trait_;
Expand All @@ -65,7 +65,7 @@ public function traitCount(DependencyMap $map) : int
*
* @return array
*/
public function afferentCoupling(DependencyMap $map) : array
public function afferentCoupling(DependencyMap $map): array
{
return $map->fromDependencies()->reduce([], function (array $afferent, Dependency $from) use ($map) {
$afferent[$from->toString()] = $map->reduce(
Expand All @@ -87,7 +87,7 @@ function (int $count, Dependency $fromOther, Dependency $to) use ($from): int {
*
* @return array
*/
public function efferentCoupling(DependencyMap $map) : array
public function efferentCoupling(DependencyMap $map): array
{
return $map->reduce([], function (array $efferent, Dependency $from, Dependency $to) use ($map) {
$efferent[$from->toString()] = $map->get($from)->count();
Expand All @@ -102,7 +102,7 @@ public function efferentCoupling(DependencyMap $map) : array
*
* @return array Key: Class Value: Range from 0 (completely stable) to 1 (completely unstable)
*/
public function instability(DependencyMap $map) : array
public function instability(DependencyMap $map): array
{
$ce = $this->efferentCoupling($map);
$ca = $this->afferentCoupling($map);
Expand Down
6 changes: 4 additions & 2 deletions src/Analyser/Parser.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Mihaeu\PhpDependencies\Analyser;

interface Parser
{
public function parse(string $code) : array;
public function parse(string $code): array;
}
2 changes: 1 addition & 1 deletion src/Analyser/StaticAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
$this->parser = $parser;
}

public function analyse(PhpFileSet $files) : DependencyMap
public function analyse(PhpFileSet $files): DependencyMap
{
$files->each(function (PhpFile $file) {
try {
Expand Down
22 changes: 11 additions & 11 deletions src/Analyser/XDebugFunctionTraceAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
class XDebugFunctionTraceAnalyser
{
const PARAMETER_START_INDEX = 11;
const FUNCTION_NAME_INDEX = 5;
public const PARAMETER_START_INDEX = 11;
public const FUNCTION_NAME_INDEX = 5;

/** @var DependencyFactory */
private $dependencyFactory;
Expand All @@ -28,9 +28,9 @@ public function __construct(DependencyFactory $dependencyFactory)
$this->dependencyFactory = $dependencyFactory;
}

public function analyse(\SplFileInfo $file) : DependencyMap
public function analyse(\SplFileInfo $file): DependencyMap
{
$fileHandle = @fopen($file->getPathname(), 'r');
$fileHandle = !empty($file->getPathname()) ? @fopen($file->getPathname(), 'r') : false;
if (!$fileHandle) {
throw new \InvalidArgumentException('Unable to open trace file for reading');
}
Expand All @@ -45,7 +45,7 @@ public function analyse(\SplFileInfo $file) : DependencyMap
return $dependencies;
}

private function extractDependenciesFromLine(DependencyMap $dependencies, string $line) : DependencyMap
private function extractDependenciesFromLine(DependencyMap $dependencies, string $line): DependencyMap
{
$tokens = $this->extractFields($line);
if ($this->isNotMethodEntryTrace($tokens)
Expand All @@ -59,35 +59,35 @@ private function extractDependenciesFromLine(DependencyMap $dependencies, string
);
}

private function isNotMethodEntryTrace(array $tokens) : bool
private function isNotMethodEntryTrace(array $tokens): bool
{
return count($tokens) <= self::PARAMETER_START_INDEX;
}

private function extractFields(string $line) : array
private function extractFields(string $line): array
{
return explode("\t", str_replace("\n", '', $line));
}

private function containsOnlyScalarValues(array $tokens) : bool
private function containsOnlyScalarValues(array $tokens): bool
{
return strpos(implode('', array_slice($tokens, self::PARAMETER_START_INDEX)), 'class ') === false;
}

private function isGlobalFunction(array $tokens) : bool
private function isGlobalFunction(array $tokens): bool
{
return strpos($tokens[self::FUNCTION_NAME_INDEX], '->') === false
&& strpos($tokens[self::FUNCTION_NAME_INDEX], '::') === false;
}

private function extractFromClass(array $tokens) : Clazz
private function extractFromClass(array $tokens): Clazz
{
$classWithoutMethod = preg_split('/(->)|(::)/', $tokens[self::FUNCTION_NAME_INDEX]);
$classParts = explode("\\", $classWithoutMethod[0]);
return $this->dependencyFactory->createClazzFromStringArray($classParts);
}

private function extractToSet(array $tokens) : DependencySet
private function extractToSet(array $tokens): DependencySet
{
return array_reduce(array_slice($tokens, self::PARAMETER_START_INDEX), function (DependencySet $set, string $token) {
if (strpos($token, 'class') === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class Application extends \Symfony\Component\Console\Application
{
const XDEBUG_WARNING = 'You are running dePHPend with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug';
public const XDEBUG_WARNING = 'You are running dePHPend with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug';

/** @var ErrorOutput */
private $errorOutput;
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/ErrorOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public function writeln(string $message): void
{
$this->symfonyStyle->getErrorStyle()->writeln($message);
}
}
}
2 changes: 1 addition & 1 deletion src/Cli/MetricsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

private function combineMetrics(array $afferentCoupling, array $efferentCoupling, array $instability) : array
private function combineMetrics(array $afferentCoupling, array $efferentCoupling, array $instability): array
{
$result = [];
foreach ($afferentCoupling as $className => $afferentCouplingValue) {
Expand Down
14 changes: 7 additions & 7 deletions src/Cli/TestFeaturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

public function runTest(string $filename) : array
public function runTest(string $filename): array
{
$_SERVER['argv'] = [0, 'text', $filename];
$application = new Application('', '', (new DependencyContainer([]))->dispatcher());
Expand All @@ -61,7 +61,7 @@ public function runTest(string $filename) : array
: [false, '<error>[✗] '.$this->extractFeatureName($filename).'<error>'];
}

private function cleanOutput(string $output) : string
private function cleanOutput(string $output): string
{
return trim(str_replace(Application::XDEBUG_WARNING, '', $output));
}
Expand All @@ -71,7 +71,7 @@ private function cleanOutput(string $output) : string
*
* @return string
*/
private function extractFeatureName(string $filename) : string
private function extractFeatureName(string $filename): string
{
preg_match_all('/((?:^|[A-Z])[a-z0-9]+)/', $filename, $matches);
return str_replace(['cli', ' feature'], '', strtolower(implode(' ', $matches[1])));
Expand All @@ -82,7 +82,7 @@ private function extractFeatureName(string $filename) : string
*
* @return string
*/
private function getExpectations(string $filename) : string
private function getExpectations(string $filename): string
{
$expectations = [];
foreach (file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
Expand All @@ -98,7 +98,7 @@ private function getExpectations(string $filename) : string
*
* @return \RegexIterator
*/
protected function fetchAllFeatureTests() : \RegexIterator
protected function fetchAllFeatureTests(): \RegexIterator
{
return new \RegexIterator(
new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/../../tests/samples')),
Expand All @@ -112,14 +112,14 @@ protected function fetchAllFeatureTests() : \RegexIterator
*
* @return array
*/
protected function runAllTests($files) : array
protected function runAllTests($files): array
{
return array_map(function ($filename) {
return $this->runTest($filename[0]);
}, iterator_to_array($files));
}

private function sortSuccessFirst() : \Closure
private function sortSuccessFirst(): \Closure
{
return function (array $x, array $y) {
if ($x[0] === true) {
Expand Down
Loading