Skip to content

Commit f57e91f

Browse files
committed
Initial working version
1 parent 13735a6 commit f57e91f

30 files changed

+2032
-1
lines changed

Diff for: .github/workflows/code-style.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Code Style
2+
3+
on: [push, pull_request, create]
4+
5+
jobs:
6+
code-style:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- name: Setup PHP
12+
uses: shivammathur/setup-php@v2
13+
with:
14+
php-version: '8.1'
15+
16+
- name: Validate composer.json
17+
run: composer validate
18+
19+
- name: Install dependencies
20+
run: composer install --prefer-dist --no-progress
21+
22+
- name: Run style check
23+
run: ./vendor/bin/php-cs-fixer fix --dry-run

Diff for: .github/workflows/static-analysis.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Code Static Analysis
2+
3+
on: [push, pull_request, create]
4+
5+
jobs:
6+
static-analysis:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
11+
- name: Setup PHP
12+
uses: shivammathur/setup-php@v2
13+
with:
14+
php-version: '8.1'
15+
16+
- name: Validate composer.json
17+
run: composer validate
18+
19+
- name: Install dependencies
20+
run: composer install --prefer-dist --no-progress
21+
22+
- name: Run static analyse
23+
run: ./vendor/bin/phpstan analyse --memory-limit=2G --error-format=github

Diff for: .github/workflows/unit-tests.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: PHPUnit
2+
3+
on: [push, pull_request, create]
4+
5+
jobs:
6+
unit-tests:
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest']
12+
php-versions: [ '7.4', '8.0', '8.1' ]
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: ${{ matrix.php-versions }}
20+
extensions: fileinfo
21+
22+
- name: Validate composer.json
23+
run: composer validate
24+
25+
- name: Install dependencies
26+
run: composer install --prefer-dist --no-progress
27+
28+
- name: Run unit tests
29+
run: ./vendor/bin/phpunit --coverage-text

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor
2+
.php-cs-fixer.cache
3+
/.idea
4+
.phpunit.result.cache
5+
composer.lock

Diff for: .php-cs-fixer.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude(['vendor'])
5+
->in([
6+
__DIR__ . '/src',
7+
__DIR__ . '/tests',
8+
]);
9+
10+
$header = 'This file is part of the composer-link plugin.
11+
12+
Copyright (c) 2021-' . date('Y') . ' Sander Visser <[email protected]>.
13+
14+
Permission is hereby granted, free of charge, to any person obtaining a copy
15+
of this software and associated documentation files (the "Software"), to deal
16+
in the Software without restriction, including without limitation the rights
17+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
copies of the Software, and to permit persons to whom the Software is furnished
19+
to do so, subject to the following conditions:
20+
21+
The above copyright notice and this permission notice shall be included in all
22+
copies or substantial portions of the Software.
23+
24+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30+
THE SOFTWARE.
31+
32+
@link https://github.com/SanderSander/composer-link';
33+
34+
$config = new PhpCsFixer\Config();
35+
return $config
36+
->setRiskyAllowed(true)
37+
->setRules([
38+
'@PSR2' => true,
39+
'strict_param' => true,
40+
'declare_strict_types' => true,
41+
'no_unused_imports' => true,
42+
'single_blank_line_at_eof' => true,
43+
'array_syntax' => ['syntax' => 'short'],
44+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
45+
'header_comment' => ['header' => $header]
46+
])->setFinder($finder);

Diff for: LICENSE.md

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

Diff for: README.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
11
# composer-link
2-
Adds ability to link local packages in composer
2+
![phpunit](https://github.com/SanderSander/composer-link/actions/workflows/unit-tests.yml/badge.svg?branch=master)
3+
4+
Adds ability to link local packages in composer for development.
5+
6+
This plugin won't alter your `composer.json` or `composer.lock` file,
7+
while maintaining the composer abilities to manage/upgrade your packages.
8+
9+
## Installation
10+
11+
This plugin can be installed globally or per project
12+
13+
Globally
14+
```
15+
composer global require sandersander/composer-link
16+
```
17+
18+
Per project:
19+
```
20+
composer require --dev sandersander/composer-link
21+
```
22+
23+
## Usage
24+
25+
The following three commands are made available by this plugin `link`, `unlink` and `linked`
26+
27+
To link a package you can use the `link` commands:
28+
```
29+
composer link ../path/to/package
30+
```
31+
32+
To unlink the package you can use the `unlink` command
33+
```
34+
composer unlink ../path/to/package
35+
```
36+
37+
To see all linked packages in your project you can use the `linked` command
38+
```
39+
composer linked
40+
```
41+
42+
## Contributing
43+
44+
Feel free to contribute, all help is welcome!
45+
46+
1. Fork it!
47+
2. Create your feature branch: `git checkout -b my-new-feature`
48+
3. Commit your changes: `git commit -am 'Add some feature'`
49+
4. Push to the branch: `git push origin my-new-feature`
50+
5. Submit a pull request :D

Diff for: composer.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "sandersander/composer-link",
3+
"description": "Link your libraries into your project for development",
4+
"type": "composer-plugin",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "SanderSander",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"ComposerLink\\": "src/"
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"Tests\\Unit\\": "tests/Unit"
20+
}
21+
},
22+
"require": {
23+
"php": ">=7.4",
24+
"composer-plugin-api": "^2.2",
25+
"league/flysystem": "^2.0|^3.0"
26+
},
27+
"require-dev": {
28+
"composer/composer": "^2.0",
29+
"friendsofphp/php-cs-fixer": "^v3.4.0",
30+
"phpstan/phpstan": "^1.4",
31+
"phpunit/phpunit": "^9.5",
32+
"phpstan/phpstan-phpunit": "^1.1"
33+
},
34+
"extra": {
35+
"class": "ComposerLink\\Plugin"
36+
},
37+
"config": {
38+
"allow-plugins": {
39+
"phpstan/extension-installer": false
40+
}
41+
}
42+
}

Diff for: phpstan.neon

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
- tests
6+
includes:
7+
- vendor/phpstan/phpstan-phpunit/extension.neon
8+
- vendor/phpstan/phpstan-phpunit/rules.neon

Diff for: phpunit.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Unit">
9+
<directory>./tests/Unit</directory>
10+
</testsuite>
11+
</testsuites>
12+
<coverage processUncoveredFiles="true">
13+
<include>
14+
<directory suffix=".php">./src</directory>
15+
</include>
16+
</coverage>
17+
</phpunit>

Diff for: src/CommandProvider.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the composer-link plugin.
5+
*
6+
* Copyright (c) 2021-2022 Sander Visser <[email protected]>.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is furnished
13+
* to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
* @link https://github.com/SanderSander/composer-link
27+
*/
28+
29+
namespace ComposerLink;
30+
31+
use Composer\IO\IOInterface;
32+
use Composer\Plugin\Capability\CommandProvider as ComposerCommandProvider;
33+
use ComposerLink\Commands\LinkCommand;
34+
use ComposerLink\Commands\LinkedCommand;
35+
use ComposerLink\Commands\UnlinkCommand;
36+
37+
class CommandProvider implements ComposerCommandProvider
38+
{
39+
protected IOInterface $io;
40+
41+
protected Plugin $plugin;
42+
43+
/**
44+
* @param array<string, mixed> $arguments
45+
*/
46+
public function __construct(array $arguments)
47+
{
48+
$this->io = $arguments['io'];
49+
$this->plugin = $arguments['plugin'];
50+
}
51+
52+
/**
53+
* @return \Composer\Command\BaseCommand[]
54+
*/
55+
public function getCommands(): array
56+
{
57+
$this->io->debug("[ComposerLink]\tInitializing commands.");
58+
59+
return [
60+
new LinkCommand($this->plugin),
61+
new UnlinkCommand($this->plugin),
62+
new LinkedCommand($this->plugin)
63+
];
64+
}
65+
}

Diff for: src/Commands/Command.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of the composer-link plugin.
5+
*
6+
* Copyright (c) 2021-2022 Sander Visser <[email protected]>.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is furnished
13+
* to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*
26+
* @link https://github.com/SanderSander/composer-link
27+
*/
28+
29+
namespace ComposerLink\Commands;
30+
31+
use Composer\Command\BaseCommand;
32+
use ComposerLink\Plugin;
33+
34+
abstract class Command extends BaseCommand
35+
{
36+
protected Plugin $plugin;
37+
38+
public function __construct(Plugin $plugin)
39+
{
40+
parent::__construct();
41+
42+
$this->plugin = $plugin;
43+
}
44+
}

0 commit comments

Comments
 (0)