Giter VIP home page Giter VIP logo

dephpend's Introduction

dePHPend lgo

Build Status Coverage Status Packagist Version License MIT PHP 7.2 Join the chat at Gitter

Detect flaws in your architecture before they drag you down into the depths of dependency hell ...

What it does

dePHPend helps with bringing your PHP projects back in shape. Over the course of a project, we usually keep adding more and more dependencies. Often hidden behind singletons or service locators, these dependencies can quickly become a maintenance (and testing!) nightmare.

dePHPend analyses your app and attempts to find everything you depend on.

With this information you can:

  • get a quick overview of how an application is structured
  • start refactoring where it's needed the most
  • track architecture violations (maybe your view shouldn't be telling the model what to do?)
  • find out why your changes are breaking tests

System Requirements

  • PHP >= 7.2
  • plantuml (UML Class diagram)

Installation

Docker

If you don't want to worry about PHP versions, composer dependencies etc. you can run dePHPend from a docker container:

# replace $PATH_TO_INSPECT with whatever path you would live to inspect
docker run --rm -v $PATH_TO_INSPECT:/inspect mihaeu/dephpend:latest text /inspect

Phive

Phive is the preferred method of installing QA tools which are not linked directly to your code. If you've never heard about it, I'd recommend you check it out. Once installed simply use:

phive install dephpend

# or

phive install --copy dephpend

Composer

You can install dePHPend globally, but this might lead to problems if other globally installed QA tools use different versions of PhpParser for instance.

composer global require dephpend/dephpend:dev-main

Manual .phar download

Download the PHAR file by selecting the latest file from GitHub Releases.

Git

git clone [email protected]:mihaeu/dephpend.git
# or
git clone https://github.com/mihaeu/dephpend.git

cd dephpend
composer install

Usage

You should almost always run QA tools without XDebug (unless you need code coverage of course). You could use a separate php.ini where XDebug is not loaded and pass that to php or you just use the -n option (this will however not load any extensions, so you have to specify those separately).

# or bin/dephpend depending on how you installed this
$ php -n -d extension=tokenizer.so -d extension=json.so -d extension=mbstring.so dephpend.phar                                                                                                 
      _      _____  _    _ _____               _ 
     | |    |  __ \| |  | |  __ \             | |
   __| | ___| |__) | |__| | |__) |__ _ __   __| |
  / _` |/ _ \  ___/|  __  |  ___/ _ \ '_ \ / _` |
 | (_| |  __/ |    | |  | | |  |  __/ | | | (_| |
  \__,_|\___|_|    |_|  |_|_|   \___|_| |_|\__,_| version 0.8.1

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display this help message
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  dsm            Generate a Dependency Structure Matrix of your dependencies
  help           Displays help for a command
  list           Lists commands
  metrics        Generate dependency metrics
  test-features  Test support for dependency detection
  text           Prints a list of all dependencies
  uml            Generate a UML Class diagram of your dependencies

Filters

Without filters the output for large apps is too bloated which is why I implemented a couple of filters to help you get the output you want:

      --no-classes                         Remove all classes and analyse only namespaces.
  -f, --filter-from=FILTER-FROM            Analyse only dependencies which originate from this namespace.
      --filter-namespace=FILTER-NAMESPACE  Analyse only classes where both to and from are in this namespace.
  -d, --depth[=DEPTH]                      Output dependencies as packages instead of single classes. [default: 0]
  -e, --exclude-regex=EXCLUDE-REGEX        Exclude all dependencies which match the (PREG) regular expression.

      --dynamic=DYNAMIC                    Adds dependency information from dynamically analysed function traces, for more information check out https://dephpend.com
  -u, --underscore-namespaces              Parse underscores in Class names as namespaces.
      --internals                          Check for dependencies from internal PHP Classes like SplFileInfo.

For more info just run php dephpend.phar help text.

Text

For quick debugging use the text command. Say you want to find out which classes depend on XYZ and what XYZ depends on, you'd run:

php dephpend.phar text src | grep XYZ

# or for more complex applications use filters
php dephpend.phar text symfony --no-classes --depth 3 --exclude-regex='/Test/'

UML

Generates UML class or package diagrams of your source code. Requires PlantUML to be installed.

You can either run

php dephpend.phar uml --output=uml.png src

# or for post-processing
php dephpend.phar uml --output=uml.png --keep-uml src

but most likely what you want to do is to use the --no-classes and --depth[=DEPTH] option. If your app has more than 20 classes, the UML will become messy if you don't use namespace instead of class level. Experiment with different depth values, but usually a depth of 2 or 3 is what you want.

Dependency Structure Matrix

If you've tried decrypting massive UML diagrams before, you know that they become very hard to interpret for large applications. DSMs allow you to get a quick overview of your application and where dependency hotspots are.

This feature is still under construction and right now it's not really fun to use. If you still want to try run

php dephpend.phar dsm src > dependencies.html

php dephpend.phar dsm src --no-classes | bcat

or pipe it to something like bcat.

Metrics

The most common package metrics have already been implemented, but there are more to come. Check them out by running the following command:

php dephpend.phar metrics src

This feature is not production ready and it's better to rely on PHP Depend for this.

Dynamic Analysis

If you want to analyse an old legacy application which makes little use of type hints and other static information and is therefore hard to analyse consider using dynamic analysis.

dePHPend can analyse XDebug trace files and add that information to the static result.

Setup

Make sure you have XDebug installed and included in your php.ini. Also make sure to include the following in the XDebug section of your php.ini:

; you should already have this somewhere in your php.ini
zend_extension=path-to-your-xdebug/xdebug.so

[xdebug]
...

; add this for tracing function calls
xdebug.auto_trace=1
xdebug.collect_params=1
xdebug.collect_return=3
xdebug.collect_assignments=1
xdebug.trace_format=1

This will slow down PHP A LOT so it is best to put it in a separate file like php-with-traces.ini and call dePHPend using php -c /path/to/php-with-traces.ini.

Usage

First create the sample data by running any PHP script (or website) with the above settings in your php.ini (set xdebug.trace_options=1 if you want to track multiple calls, but this will make the trace file grow BIG).

# use your tests (but make sure to exclude unwanted data using filters)
php -c php-with-traces.ini vendor/bin/phpunit

# or using PHP's inbuilt server etc.
php -c php-with-traces.ini -S localhost:8080

The better the sample run and the more of your application it covers, the better the results are going to be. After that process the trace file using the --dynamic option.

php dephpend.phar text src                  \
    --no-classes                            \
    --filter-from=Mihaeu\\PhpDependencies   \
    --exclude-regex='/(Test)|(Mock)/'       \
    --dynamic=/tmp/traces.12345.xt          

You will probably always end up using filters like --filter-from because the dynamic parser parses everything not just the stuff from the directory provided. So all third party stuff is going to show up as well.

The trace file, by default, will be in your system's temporary folder. This can be changed by setting xdebug.trace_output_dir and xdebug.trace_output_name in your php.ini (see XDebug Function Traces).

Examples

Architecture Constraints

Using the text command it is fairly straightforward to create a script which validates your architecture:

#!/usr/bin/env php
<?php

$output = shell_exec('php dephpend.phar text src --no-classes');
$constraints = [
    'OS --> .*Analyser',
    'Analyser --> .*OS',
];
if (preg_match('/('.implode(')|(', $constraints).')/', $output)) {
    echo 'Architecture violation'.PHP_EOL;
    exit(1);
}

Save this in your .git/hooks/pre-commit or .git/hooks/pre-push and you'll never violate your project managers trust again. You could also include this on every Travis or Jenkins CI build, but I prefer to not bother the CI when I can check it myself.

Architecture Timeline

Executing dePHPend's metric command on any branch git log --pretty=%H and using convert -delay 100 -loop 0 *.png dephpend-timeline.gif you can create a nice animation detailing the evolution of your architecture:

dePHPend Timeline

How it all works

Basically the process can be broken down into four steps (the actual work is a bit more complicated and for those interested, I'll publish a paper about it, later this year):

  • find all relevant PHP files
  • generate an abstract syntax tree using php-parser by the awesome Nikita Popov
  • traverse the tree, gathering dependencies along the way
  • pass the information to a formatter

Supported Features

Check out tests/features for examples of supported features or run bin/dephpend test-features for a list of supported detection features:

[✓]  creating objects
[✓]  using traits
[✓]  extending other classes
[✓]  type hints in method arguments
[✓]  param return throws in doc comment
[✓]  implementing interfaces
[✓]  php7 return value declaration
[✓]  call to static method
[✗]  return value of known method
[✗]  method arguments and return value from doc
[✗]  known variable passed into method without type hints
[✗]  creating objects from strings

Troubleshooting

Not enough RAM

The PHP-Parser can take up lots of RAM for big applications. You can adjust the RAM limit in your php.ini, but a safer solution would be to call dePHPend by adding php -n -d memory_limit=1024M dephpend.phar ....

License

See LICENSE file

dephpend's People

Contributors

fuco1 avatar hkdobrev avatar mihaeu avatar pierstoval avatar rojoangel avatar sauerbrei avatar sebastianbergmann avatar sebastianheuer avatar szepeviktor avatar tobiasstadler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dephpend's Issues

Optionally mark visibility of a dependency in output

It would be useful to me to be able to distinguish between dependencies of different visibility, in particular "public" dependencies (subclassing, implemented interfaces, public method signatures) and "private" dependencies (private method signatures, use in method bodies). For a large and messy code base like MediaWiki, this would allow further analysis to distinguish between that are hard to fix (public dependencies) and things that are easy to fix (private dependencies).

This is a feature I so far have not seen in any static analysis tool. I'm wondering why, I can't be the only one who'd find this useful. Perhaps it's because static analysis tools are mostly used by design purists, and options to filter out some kinds of issues as "less bad" does not appeal to them?... When working with clean code, this kind of thing isn't needed. When trying to clean up an organically grown tangle of half a million lines, it would be great to have...

Anyway. In addition to "private" and "public", there are a few in-between visibilities to be consider:

  • "constructor" (use in the constructor signature). Technically public, but constructor calls may be restricted to wiring code by convention, making it "internal" in a sense. For this to me useful, constructor usage should not be considered "public".
  • "protected" - may have to be treated as private or public, depending on context.
  • "internal" if the class or method has the @internal tag
  • "deprecated" if the class or method has the @deprecated tag. This essentially makes this an extension of or alternative to issue #42.

In "text" output, with --visibility enabled, this flags could form a third column, perhaps using the form
Foo --> Bar @Private
FooBar --> Foo @public
FooBar --> Frob @Protected @deprecated

In GML (as proposed in #41) this could trivially be represented as additional attributes on the edges.

Allow filtering out dependencies introduced by deprecated methods and classes.

When refactoring a code base that needs to maintain a stable interface, it's often necessary to keep undesirable dependencies in deprecated methods until some later release. It would be useful to be able to see what the dependencies would look like with all the deprecated stuff removed. The respective filter would skip all classes and methods with the @deprecated tag in the documentation.

Architecture DSL

Quick draft:

<?php

beforeClass() {
	// setup
	$fileSet = $finder->find(__DIR__ . '/src')
		->addAll($finder->find(__DIR__ . '/vendor'));
	$dependencies = $staticAnalyser->analyse($fileSet);

	// setup shorthand
	analyse('path1', 'path2');
}

// test
test() {
	$models = defineLayer()
		->from('Some\Namespace\Bla')
		->from('/special.*regex/');

	$views = defineComponent()
		->from('')
		->from('');

	$controllers
		->dependsOn($models)
		->but()
		->mayNotDependOn($views);

	$util
		->mayNotHaveDependencies();

	$views
		->mayNotBeDependentOn();

	package('Vendor/Namespace')
		->mayNotDependOn()
		->classesFromDir(__DIR__ . '/../vendor');

	classesMatching('/.*Service.*/')
		->mayOnlyDependOn()
		->classesMatching('/.*Provider.*/');
}

Assertions using xUnit i.e. PHPUnit Framework Assertions.

It cannot parse this php 8 code.

final class SomeAction implements ActionInterface
{
    public function __construct(
        private SomeService $domain,
        private Request $request,
    ) {}
}

Wrong argument on ensureDestinationIsWritable()

On version 0.6.1, tried to run bin/dephpend dot myprojectpath and got

Argument 1 passed to Mihaeu\PhpDependencies\Cli\BaseCommand::ensureDestinationIsWritable() must be of the type string, null given, called in /mydir/dephpend/src/Cli/DotCommand.php on line 51
[/mydir/dephpend/src/Cli/BaseCommand.php at line 138]

Unable to execute this tool

Hello.

I have installed this tool via phive. Even if it installed dephpend v0.7.0, dephpend --version reports version 0.6.3, which feels a bit odd (maybe that phar is messed up?)

When I try to execute this library on a Symfony 5.1 project with PHP 7.4 (which is pretty big), I keep getting the following error:

$ dephpend text src
PHP Warning:  Undefined array key 314 in phar:///usr/local/bin/dephpend/vendor/nikic/php-parser/lib/PhpParser/Lexer.php on line 293
Something went wrong, this shouldn't happen. Please take a minute and report this issue: https://github.com/mihaeu/dephpend/issues

PhpParser\Lexer::getNextToken(): Return value must be of type int, null returned

[phar:///usr/local/bin/dephpend/vendor/nikic/php-parser/lib/PhpParser/Lexer.php at line 333]

Applying -vvv flag does not affect the output at all.

AOP for dynamic analysis?

Hi,

I saw you're into dynamic analysis which I find really interesting. Have you ever considered using an AOP library plus Reflection to obtain param and return types?

To be honest, it's just a naive idea. I can't even say if it's better or worse than xdebug performance-wise.

Release Artifact: Can't check signature: No public key

I actually like to verify gpg keys. But looks like you did not provide a public key...

gpg --verify dephpend-0.6.0.phar.asc 
gpg: assuming signed data in 'dephpend-0.6.0.phar'
gpg: Signature made Do 11 Apr 2019 17:48:01 CEST
gpg:                using RSA key 22BD58D0E3B969122E5E1CF22BCCDC2E41A6C1AF
gpg:                issuer "[email protected]"
gpg: Can't check signature: No public key

Syntax error message does not include filename

The error message shown below is missing information about the source code file it refers to:

Sorry, we could not analyse your dependencies, because the sources contain syntax errors:

Syntax error, unexpected T_STRING on line 1

UML generation

The results of the prototype showed that Graphviz output, without putting lots of effort into styling, is useless.

PlantUML uses Graphviz for node positioning, but takes care of styling and already provides UML class diagram elements.

@startuml
Class01 <|-- Class02
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 -- Class10
@enduml

A prototype of php-dependencies generated the following output:

sample

For the alpha version:

  • composition and <<call>> dependencies should be added to the graph.
  • the tool should check if PlantUML is available and either be shipped with PlantUML packaged or offer to download it and check for Java support

When reporting syntax errors, mention the file name

Currently, when a syntax error is found in the code base, the error report looks like this:

  Sorry, we could not analyse your dependencies, because the sources contain syntax errors:
  Syntax error, unexpected T_SL on line 1235

There is no indication what file the error is in, which is problematic in a large code base. This is especially annoying if the error can't easily be found with other tools, because it's not a "real" syntax error, but rather an incompatibility with an obscure language feature or syntax introduced by a new version of php.

Somewhere on the stack that reports the error, information exists about which file was currently being processed. It would be helpful to include that information in the output.

Error in text mode

Similar to #56

Using: docker, composer: 0.6.2, composer: dev-master

Argument 1 passed to Mihaeu\PhpDependencies\Analyser\DependencyInspectionVisitor::addName() must be an instance of PhpParser\Node\Name, instance of PhpParser\Node\Expr\ArrayDimFetch given, called in /root/.composer/vendor/dephpend/dephpend/src/Analyser/DependencyInspectionVisitor.php on line 90

Set namespaces for legacy apps

Legacy apps are not using namespaces but instead use pseudo namespaced classes like My_Company_Package_Subpackage_Class.

For the generation of package scoped output (not outputting every single class) the user should be able to specify a namespace delimiter e.g. --namespace-delimiter="_"

Support for DI containers

Start with:

  • Pimple
  • Symfony\DependencyInjection (allows Yaml and XML configuration 😞)
  • Laravel (probably the toughest)

Error running text mode

I'm running this command

docker run --rm -v <abs_path>:/inspect mihaeu/dephpend:latest text /inspect

and I'm getting this output

`Something went wrong, this shouldn't happen. Please take a minute and report this issue: https://github.com/mihaeu/dephpend/issues

Argument 1 passed to Mihaeu\PhpDependencies\Analyser\DependencyInspectionVisitor::addName() must be an instance of PhpParser\Node\Name, instance of PhpParser\Node\Expr\PropertyFetch given, called in /dephpend/src/Analyser/DependencyInspectionVisitor.php on line 89

[/dephpend/src/Analyser/DependencyInspectionVisitor.php at line 97]`

Compability with Symfony 4

Currently this package is incompatible with Symfony 4, due to composer.json:

        "symfony/console": "^2.0 || ^3.0",
        "symfony/event-dispatcher": "^2.0 || ^3.0"

Throw RuntimeException for --help option

Inside my container:

php /project/tools/dephpend --help
PHP Fatal error:  Uncaught Symfony\Component\Console\Exception\RuntimeException: Not enough arguments (missing: "source"). in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php:83
Stack trace:
#0 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php(49): Symfony\Component\Console\Input\Input->validate()
#1 phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/ArgvInput.php(63): Symfony\Component\Console\Input\Input->__construct(Object(Symfony\Component\Console\Input\InputDefinition))
#2 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/Cli/Application.php(144): Symfony\Component\Console\Input\ArgvInput->__construct(Array, Object(Symfony\Component\Console\Input\InputDefinition))
#3 phar:///root/.phive/phars/dephpend-0.3.0.phar/src/Cli/Application.php(41): Mihaeu\PhpDependencies\Cli\Application->createFakeInput()
#4 phar:///root/.phive/phars/dephpend-0.3.0.phar/bin/dephpend(33): Mihaeu\PhpDependencies\Cli\Application->__construct('      _       in phar:///root/.phive/phars/dephpend-0.3.0.phar/vendor/symfony/console/Input/Input.php on line 83

In my opinion it's not quite right to throw the exception here and does not look professional. Maybe replace it by message "Command/Option/Argument not found"?

dephpend --version throws error

dephpend.phar, version 0.5.0

# dephpend.phar --version
PHP Fatal error:  Uncaught Symfony\Component\Console\Exception\RuntimeException: Not enough arguments (missing: "source"). in phar:///usr/local/bin/dephpend.phar/vendor/symfony/console/Input/Input.php:76
Stack trace:
#0 phar:///usr/local/bin/dephpend.phar/vendor/symfony/console/Input/Input.php(42): Symfony\Component\Console\Input\Input->validate()
#1 phar:///usr/local/bin/dephpend.phar/vendor/symfony/console/Input/ArgvInput.php(61): Symfony\Component\Console\Input\Input->__construct(Object(Symfony\Component\Console\Input\InputDefinition))
#2 phar:///usr/local/bin/dephpend.phar/src/Cli/Application.php(150): Symfony\Component\Console\Input\ArgvInput->__construct(Array, Object(Symfony\Component\Console\Input\InputDefinition))
#3 phar:///usr/local/bin/dephpend.phar/src/Cli/Application.php(41): Mihaeu\PhpDependencies\Cli\Application->createFakeInput()
#4 phar:///usr/local/bin/dephpend.phar/bin/dephpend(33): Mihaeu\PhpDependencies\Cli\Application->__construct('      _      __...', '0.5.0', Object(Mihaeu\PhpDependencies\DI\DI))
#5 /u in phar:///usr/local/bin/dephpend.phar/vendor/symfony/console/Input/Input.php on line 76

DSM not counting correctly

The DSM right now counts how many dependencies one package has to another package (using --only-namespaces). By definition, this can only amount to one. The actual important information for the package level is how many classes of another package a package is depending on.

Improve --underscore-namespaces to fix invalid class names (^number)

--underscore-namespaces option is very usefull for projects that don't use namespaces to allow component/package level view. Unfortunataly in such project we can have classes like My_Class_2You . When "namespaced", it will result into invalid classname because it starts with number: My/Class/2You

It causes Fatal error even when I'm not interested in classes (--no-classes used).

It would be nice to come with solution for this issue.

Suggestions:

  1. Autofix class names in mapNamespaces() method always
  2. Fix classes when specified e.g. with --underscore-namespaces-fix
  3. Or more specific - prefixing bad class names --underscore-namespaces-classfix-prefix (that would help to classes that start with number)
  4. Or some kind of regular expression modification --underscrore-namespaces-fix-regex of invalid classes?

.. or maybe you have a better idea how to fix such issue ;)

There might be another invalid class name situation, but this one with the number at the beginning is the one which currently hinders me from using dephpend on the project I'm dealing with (without being forced to refactor such code).

Don't treat class name literals as dependencies

Class name literals, like FooBar::class, should not be treated as a dependency on the class FooBar. Such literals are really just syntactic sugar for string literals like "FooBar", they don't require the class to be loaded, or even to exist at all.

Technically, class name literals are a dependency on the class name, as they have to be updated when the class is renamed. If this kind of dependency should still be tracked, the mechanism for marking the dependency type suggested in #43 could be used to mark such dependencies as "name".

Support plantuml.jar

Support plantuml.jar for those who can't or don't want to install it on their system.

Syntax error

Running ./dephpend.phar metrics gives me a syntax error:

[PhpParser\Error]
Syntax error, unexpected T_ELLIPSIS, expecting T_STRING or T_VARIABLE or '{' or '$' on line 145

(dePHPend Phar Sept 15th, 12:30). Other commands seem to have the same problem.

Incompatible with symfony/event-dispatcher 4.3

The composer.json file says "symfony/event-dispatcher": "^2.0 || ^3.0 || ^4.0", but the way the Dispatcher is implemented is apparently incompatible with versions 4.3 and later. It seems like no action is performed at all, since the dispatch() method never gets called. With symfony/event-dispatcher 4.2.10, things still work as expected.

Add phar to phive

  • get SSL certificate for server
  • generate phar page using Sebastian's generator
  • sign the phar
  • fork and add the phive repo info

phar generation

Add phar generation to the build process to simplify distribution and testing.

Replace Symfony console

Symfony's console component makes proper dependency (constructor) injection very difficult:

  • a Command's arguments and options are coupled to the Command
  • verifying and accessing input requires the InputDefinition of a Command
  • therefore injecting dependencies into a Command is not possible if the dependencies require information from the Input

Right now there's an ugly hack which pre-creates the requested Command and then discards it after parsing the Input.

This in addition to the difficulties and extra effort required in testing the Commands makes an custom implementation worthwhile.

Format DSM

The current table formatting makes the DSM utterly useless, because it's impossible to see anything.

  • make the <th> align the text vertically
  • highlight clicked cells

Make --output optional

All commands, including those producing binary output (e.g. .png) can output to stdout directly. This would allow for one line calls like

bin/dephpend uml src | display

instead of having to write it to an intermediate file.

Update to Symfony 5.

This will be nice if this package is compatible with Symfony version 5.0.

This only a matter of update the composer.json file:

"require": {   
    "symfony/console": "^2.0 || ^3.0 || 4.0.* || 4.1.* || 4.2.* || 5.0.*",
    "symfony/event-dispatcher": "^2.0 || ^3.0 || ^4.0 || 5.0.*"
},

Uncaught TypeError: Argument 1 passed to Mihaeu\PhpDependencies\Dependencies\DependencyFactory::createClazzFromStringArray() must be of the type array, null given

$ git clone [email protected]:mihaeu/dephpend.git
$ cd dephpend
$ composer update
$ cd ...
$ git clone [email protected]:symfony/symfony.git
$ cd symfony
$ composer update
$ ../dephpend/bin/dephpend text .
PHP Notice:  Undefined property: PhpParser\Node\Stmt\Class_::$namespacedName in /usr/local/src/dephpend/src/Analyser/DependencyInspectionVisitor.php on line 188
PHP Notice:  Trying to get property of non-object in /usr/local/src/dephpend/src/Analyser/DependencyInspectionVisitor.php on line 188
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Mihaeu\PhpDependencies\Dependencies\DependencyFactory::createClazzFromStringArray() must be of the type array, null given, called in /usr/local/src/dephpend/src/Analyser/DependencyInspectionVisitor.php on line 188 and defined in /usr/local/src/dephpend/src/Dependencies/DependencyFactory.php:14
Stack trace:
#0 /usr/local/src/dephpend/src/Analyser/DependencyInspectionVisitor.php(188): Mihaeu\PhpDependencies\Dependencies\DependencyFactory->createClazzFromStringArray(NULL)
#1 /usr/local/src/dephpend/src/Analyser/DependencyInspectionVisitor.php(59): Mihaeu\PhpDependencies\Analyser\DependencyInspectionVisitor->setCurrentClass(Object(PhpParser\Node\Stmt\Class_))
#2 /usr/local/src/dephpend/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(92): Mihaeu\PhpDependencies\Analyser\DependencyInspectionVisitor->enterNode(Object(PhpParser\Node\Stmt\Class_))
#3 /usr/local/src/dephpend/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(101): PhpParser\NodeTraverser->traverseNo in /usr/local/src/dephpend/src/Dependencies/DependencyFactory.php on line 14

jdepend metrics

This feature depends on how many dependencies were detected. The math however does not change, so including this as a core feature for the alpha release makes sense.

  • Number of Classes and Interfaces
  • Afferent Couplings (Ca)
  • Efferent Couplings (Ce)
  • Abstractness (A)
  • Instability (I)
  • Distance from the Main Sequence (D)
  • Package Dependency Cycles

Reference: jdepend documentation

Dependency detection for explicit dependencies

The following types of *explicit dependencies (i.e. no dynamic new $$$$var();) should be detected:

  • <<create>> dependencies (i.e. new X())
  • <<call>> dependencies to globals and static dependencies
  • <<call>> dependencies to injected dependencies (either through constructor or method injection)

Questions:

  • are superglobals like $_POST relevant ($_GLOBALS is, but will not be supported in the alpha version)?

Support GML output

While the plain text output of dependencies is nice for processing with grep, it would be nice to have an output format that can be used directly with more powerful graph analysis frameworks, such as graph-tool. GML seems to be a good candidate, since it's human readable and easy to generate.

Docker container rebuild

There is an issue with docker container.
Image needs to be rebuild one in docker hub is no the one in Dockerfile. Automated build would be great also in docker hub there is no link back to github or builded Dockerfile, this looks kind a bad.

Also would be great if entry point has raised php memory limit. Or in readme could be example how to raise memory limit with docker by overriding entry point.

 docker run -it -v $PWD/src:/inspect --entrypoint "/usr/local/bin/php" mihaeu/dephpend:latest -n -d memory_limit=-1 /usr/src/dephpend/bin/dephpend text /inspect

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.