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

Fix issue with ext-ds #88

Merged
merged 3 commits into from Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .docker/php7.4/Dockerfile
Expand Up @@ -10,6 +10,8 @@ RUN apt-get update \
libzip-dev \
&& docker-php-ext-install zip \
&& docker-php-ext-install opcache \
&& pecl install -o ds \
&& echo "extension=ds.so" > /usr/local/etc/php/conf.d/ds.ini \
&& rm -r /var/lib/apt/lists/*

RUN pecl install xdebug \
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/validate-code.yml
Expand Up @@ -24,7 +24,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer
tools: composer, pecl
extensions: ds

- name: Validate composer.json and composer.lock
run: composer validate
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## [Unreleased]
### Fixed
- Fixed an issue where `ext-ds` classes where not recognized as used

## [0.7.3] - 2020-05-19
### Added
- Added workflow to verify integrity of build `phar` file
Expand Down
22 changes: 9 additions & 13 deletions Makefile
@@ -1,35 +1,31 @@
CONTAINER=composer-unused-7.4

up:
if [ "$(shell docker-machine status default)" != 'Running' ]; then \
docker-machine start default; \
fi;
eval ${docker-machine env}
eval ${shell docker-machine env}
docker-compose up -d

down:
docker-compose down

7.4:
eval $(export COMPOSER_UNUSED_PHP_VERSION=composer-unused-7.4)

7.3:
eval $(export COMPOSER_UNUSED_PHP_VERSION=composer-unused-7.3)

install:
docker exec -it $(COMPOSER_UNUSED_PHP_VERSION) composer install
docker exec -it $(CONTAINER) composer install

update:
docker exec -it $(COMPOSER_UNUSED_PHP_VERSION) composer update
docker exec -it $(CONTAINER) composer update

check: csfix cs phpunit analyse

phpunit:
docker exec -it $(COMPOSER_UNUSED_PHP_VERSION) vendor/bin/phpunit
docker exec -it $(CONTAINER) vendor/bin/phpunit

analyse:
docker exec -it $(COMPOSER_UNUSED_PHP_VERSION) vendor/bin/phpstan analyse
docker exec -it $(CONTAINER) vendor/bin/phpstan analyse

cs:
docker exec -it $(COMPOSER_UNUSED_PHP_VERSION) vendor/bin/phpcs
docker exec -it $(CONTAINER) vendor/bin/phpcs

csfix:
docker exec -it $(COMPOSER_UNUSED_PHP_VERSION) vendor/bin/phpcbf
docker exec -it $(CONTAINER) vendor/bin/phpcbf
3 changes: 2 additions & 1 deletion src/Parser/PHP/Strategy/PhpExtensionStrategy.php
Expand Up @@ -104,8 +104,9 @@ public function extractNamespaces(Node $node): array
private function getNameFromNode(Node $node): string
{
if ($node instanceof Node\Name\FullyQualified) {
return $node->parts[0];
return implode('\\', $node->parts);
}

if ($node instanceof Node\Stmt\UseUse) {
return $node->name->parts[0];
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Integration/Parser/PHP/NodeVisitorTest.php
Expand Up @@ -156,6 +156,11 @@ public function itShouldParseUsagesDataProvider(): array
'inputFile' => ASSET_DIR . '/TestFiles/PhpExtensionStrategy/ClassWithCore.php',
'strategy' => new PhpExtensionStrategy(['Core'], new NullLogger())
],
'PhpExtensionParseStrategyShouldReturnQualifiedNamespace---11' => [
'expectedUsedNamespaces' => ['ext-ds'],
'inputFile' => ASSET_DIR . '/TestFiles/PhpExtensionStrategy/ClassWithDs.php',
'strategy' => new PhpExtensionStrategy(['ds'], new NullLogger())
],
];
}

Expand Down
13 changes: 13 additions & 0 deletions tests/assets/TestFiles/PhpExtensionStrategy/ClassWithDs.php
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace TestFile {
class ClassWithDs
{
public function foo()
{
$map = new \Ds\Map();
}
}
}