Skip to content

Commit c9e7372

Browse files
committed
chore: initial
0 parents  commit c9e7372

18 files changed

+604
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.idea
2+
/vendor
3+
composer.lock

.repo_ignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Global ignore defaults
2+
**/node_modules/
3+
**/.npm/
4+
**/__pycache__/
5+
**/.pytest_cache/
6+
**/.mypy_cache/
7+
**/vendor/
8+
9+
# Build caches
10+
**/.gradle/
11+
**/.nuget/
12+
**/.cargo/
13+
**/.stack-work/
14+
**/.ccache/
15+
16+
# IDE and Editor caches
17+
**/.idea/
18+
**/.vscode/
19+
**/*.swp
20+
**/*~
21+
22+
# Temp files
23+
**/*.tmp
24+
**/*.temp
25+
**/*.bak
26+
27+
**/*.meta
28+
**/package-lock.json
29+
**/composer.lock

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Nuno Maduro <enunomaduro@gmail.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

bin/codemap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
require __DIR__ . '/../vendor/autoload.php';
7+
8+
use Kauffinger\Codemap\CodemapCommand;
9+
10+
exit((new CodemapCommand())->__invoke($argv));

composer.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "kauffinger/php-codemap",
3+
"description": "Generate codemap surface text for PHP code",
4+
"keywords": ["php", "codemap", "repoprompt"],
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Konstantin Auffinger",
9+
"email": "konstantinauffinger@gmail.com"
10+
}
11+
],
12+
"bin": [
13+
"bin/codemap"
14+
],
15+
"require": {
16+
"php": "^8.3.0",
17+
"nikic/php-parser": "^5.4"
18+
},
19+
"require-dev": {
20+
"laravel/pint": "^1.18.1",
21+
"pestphp/pest": "^3.7",
22+
"pestphp/pest-plugin-type-coverage": "^3.1",
23+
"phpstan/phpstan": "^1.12.7",
24+
"rector/rector": "^1.2.8",
25+
"symfony/var-dumper": "^7.1.6"
26+
},
27+
"autoload": {
28+
"psr-4": {
29+
"Kauffinger\\Codemap\\": "src/"
30+
}
31+
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"Tests\\": "tests/"
35+
}
36+
},
37+
"minimum-stability": "stable",
38+
"prefer-stable": true,
39+
"config": {
40+
"sort-packages": true,
41+
"preferred-install": "dist",
42+
"allow-plugins": {
43+
"pestphp/pest-plugin": true
44+
}
45+
},
46+
"scripts": {
47+
"refacto": "rector",
48+
"lint": "pint",
49+
"test:refacto": "rector --dry-run",
50+
"test:lint": "pint --test",
51+
"test:types": "phpstan analyse --ansi",
52+
"test:unit": "pest --colors=always --coverage --parallel --min=100",
53+
"test": [
54+
"@test:refacto",
55+
"@test:lint",
56+
"@test:types",
57+
"@test:unit"
58+
]
59+
}
60+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Test Suite">
9+
<directory suffix="Test.php">./tests</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory suffix=".php">./app</directory>
15+
<directory suffix=".php">./src</directory>
16+
</include>
17+
</source>
18+
</phpunit>

pint.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"array_push": true,
5+
"backtick_to_shell_exec": true,
6+
"declare_strict_types": true,
7+
"fully_qualified_strict_types": true,
8+
"global_namespace_import": {
9+
"import_classes": true,
10+
"import_constants": true,
11+
"import_functions": true
12+
},
13+
"ordered_class_elements": {
14+
"order": [
15+
"use_trait",
16+
"case",
17+
"constant",
18+
"constant_public",
19+
"constant_protected",
20+
"constant_private",
21+
"property_public",
22+
"property_protected",
23+
"property_private",
24+
"construct",
25+
"destruct",
26+
"magic",
27+
"phpunit"
28+
],
29+
"sort_algorithm": "none"
30+
},
31+
"ordered_interfaces": true,
32+
"ordered_traits": true,
33+
"protected_to_private": true,
34+
"strict_comparison": true
35+
}
36+
}

rector.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__.'/src',
10+
__DIR__.'/tests',
11+
])
12+
// uncomment to reach your current PHP version
13+
->withPhpSets()
14+
->withPreparedSets(
15+
deadCode: true,
16+
codeQuality: true,
17+
earlyReturn: true,
18+
)
19+
->withTypeCoverageLevel(0);

src/CodemapCommand.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Kauffinger\Codemap;
6+
7+
final class CodemapCommand
8+
{
9+
/**
10+
* Invokes the codemap command.
11+
*
12+
* @param array $args The command-line arguments (if any).
13+
* @return int Exit code.
14+
*/
15+
public function __invoke(array $args): int
16+
{
17+
// Shift off the script name
18+
array_shift($args);
19+
20+
// If no paths are provided, default to scanning the src folder
21+
if ($args === []) {
22+
$args = [__DIR__.'/../src'];
23+
}
24+
25+
$pathsToScan = $args;
26+
$outputFile = __DIR__.'/../codemap.txt';
27+
28+
$generator = new CodemapGenerator;
29+
$allResults = [];
30+
31+
foreach ($pathsToScan as $path) {
32+
if (! file_exists($path)) {
33+
echo "Warning: Path '$path' does not exist.".PHP_EOL;
34+
35+
continue;
36+
}
37+
38+
$results = $generator->generate($path);
39+
foreach ($results as $fileName => $data) {
40+
$allResults[$fileName] = $data;
41+
}
42+
}
43+
44+
$formatter = new TextCodemapFormatter;
45+
$output = $formatter->format($allResults);
46+
47+
file_put_contents($outputFile, $output);
48+
echo "Codemap generated at: {$outputFile}".PHP_EOL;
49+
50+
return 0;
51+
}
52+
}

0 commit comments

Comments
 (0)