patbator/lachesis

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:project

0.1 2024-07-29 21:26 UTC

This package is auto-updated.

Last update: 2024-08-29 19:41:43 UTC


README

Lachesis (/ˈlækɪsɪs/ LAK-iss-iss; Ancient Greek: Λάχεσις, romanized: Lákhesis, lit. 'disposer of lots'; from λαγχάνω lanchánō, 'to obtain by lot, by fate, or by the will of the gods'), in ancient Greek religion, was the middle of the Three Fates, or Moirai; the others were her sisters, Clotho and Atropos. Normally seen clothed in whiteLachesis is the measurer of the thread spun on Clotho's spindle, and in some texts, determines Destiny, or thread of life.

-- Wikipedia contributors, "Lachesis," Wikipedia, The Free Encyclopedia, https://en.wikipedia.org/w/index.php?title=Lachesis&oldid=1169650823 (accessed July 28, 2024).

A tool to discover how your PHP code is weaved.

Install

Get this source code and then use Composer:

composer install

Usage

This tool provide a command in its bin directory.

bin/lachesis analyze <baseDirectory>

Lachesis will find all PHP files recursively starting at the specified baseDirectory. For each file it will detect classes definitions and collect them as well as their collaborators i.e. :

  • parent (extends), setting current class as child of it
  • implemented interfaces, setting current class/interface as implementor of them
  • received types as method parameters, setting current class/interface as receiver of them
  • returned types as method return, setting current class/interface as returner of them

We end with a fabric describing reciprocal links between:

  • parent <-> children (extends)
  • implementations <-> implementors
  • received <-> receivers
  • returned <-> returners

The analyze command output a JSON array representative of the fabric on STDOUT that you can save in a file:

bin/lachesis analyze /path/to/php/source/code > /path/to/desired/output_file.json

Output example for Lachesis Fabric class:

{
    "id": "47c7f147c86ec190a6cb3b700bc9fd31b8688b85", // generated id from FQN
    "name": "Lachesis\\Fabric",
    "parent": null, // extends nothing
    "implementations": [
        { // implement PhpParser\NodeVisitor
            "id": "05bef068d987505bdfc10cb371a8f5bb84e73e16",
            "name": "PhpParser\\NodeVisitor"
        }
    ],
    "implementors": [], // implemented by nothing as it is not an interface
    "received": [
        { // received in __construct
            "id": "88bc6161bb25a2869d6980ee6fb71c6276959c01",
            "name": "PhpParser\\Parser"
        },
        { // received in __construct
            "id": "b55c17f51da4bc7cee24c1234d7b2fae57f156fb",
            "name": "PhpParser\\NodeTraverserInterface"
        },
        { // received in eachNodeDo
            "id": "84e77ec95c5a92eb909c6ac217e1a65e9bf9d350",
            "name": "Closure"
        },
        { // received in enterNode and leaveNode
            "id": "00eb6b01a21c654b4ad34ba160edb47d4fe4f960",
            "name": "PhpParser\\Node"
        }
    ],
    "receivers": [], // nobody receive it 
    "returned": [], // return nothing
    "returners": [] // nobody return it
}

License

Copyright (c) 2024 Patrick Barroca patrick.barroca@gmail.com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/gpl-3.0.html.