Skip to content

Commit

Permalink
Run CI
Browse files Browse the repository at this point in the history
  • Loading branch information
apfelbox committed Jun 4, 2024
1 parent d95d92f commit 5e3f620
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 79 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ jobs:
php --version
php -r 'foreach (get_loaded_extensions() as $extension) echo $extension . " " . phpversion($extension) . PHP_EOL;'
- name: Install Composer
run: composer install --optimize-autoloader --classmap-authoritative --no-interaction

- name: Run Linters
run: composer run-script lint

- name: Run Tests
run: composer run-script test

- name: "Install Composer: Library / Composer Normalize"
run: composer install --optimize-autoloader --classmap-authoritative --no-interaction
working-directory: _init/library/vendor-bin/c-norm
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/.php-cs-fixer.cache
/composer.lock
/vendor
/vendor-bin/*/composer.lock
/vendor-bin/*/vendor
35 changes: 28 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@
{
"name": "21torr/janus",
"type": "lib",
"description": "Code style, encoded as rules for common tools.",
"homepage": "https://github.com/21TORR/janus-php",
"license": "BSD-3-Clause",
"type": "lib",
"authors": [
{
"name": "21TORR",
"homepage": "https://www.21torr.com/"
}
],
"homepage": "https://github.com/21TORR/janus-php",
"require": {
"php": ">= 8.3",
"21torr/cli": "^1.2",
"symfony/console": "^7.0",
"symfony/process": "^7.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"roave/security-advisories": "dev-latest"
},
"bin": [
"bin/janus"
],
"autoload": {
"psr-4": {
"Janus\\": "src/"
}
},
"bin": [
"bin/janus"
],
"config": {
"sort-packages": true,
"allow-plugins": {
"bamarni/composer-bin-plugin": true,
"ergebnis/composer-normalize": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
"extra": {
"bamarni-bin": {
"bin-links": false,
"forward-command": true
}
},
"scripts": {
"fix-lint": [
"@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --ansi",
"vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --no-interaction --ansi"
],
"lint": [
"@composer bin c-norm normalize \"$(pwd)/composer.json\" --indent-style tab --indent-size 1 --dry-run --ansi",
"vendor-bin/cs-fixer/vendor/bin/php-cs-fixer fix --diff --config vendor-bin/cs-fixer/vendor/21torr/php-cs-fixer/.php-cs-fixer.dist.php --dry-run --no-interaction --ansi"
],
"test": [
"vendor-bin/phpstan/vendor/bin/phpstan analyze -c phpstan.neon . --ansi"
]
}
}
}
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- phpstan/lib.neon
5 changes: 3 additions & 2 deletions src/Command/InitializeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public function __construct ()
/**
* @inheritDoc
*/
protected function configure ()
protected function configure () : void
{
$this
->setDescription("Initializes a given command")
->addArgument(
"type",
InputArgument::REQUIRED,
"The project type to initialize",
default: null,
suggestedValues: [
"symfony",
"library",
Expand All @@ -45,10 +46,10 @@ protected function execute (InputInterface $input, OutputInterface $output) : in
$io = new TorrStyle($input, $output);
$io->title("Janus: Initialize");


try
{
$type = $input->getArgument("type");
\assert(\is_string($type));

$initializer = match ($type)
{
Expand Down
63 changes: 0 additions & 63 deletions src/Command/LegacyCommand.php

This file was deleted.

7 changes: 7 additions & 0 deletions src/Exception/InvalidCallException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types=1);

namespace Janus\Exception;

final class InvalidCallException extends \InvalidArgumentException implements JanusException
{
}
27 changes: 20 additions & 7 deletions src/Initializer/InitializeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct (
private TorrStyle $io,
)
{
$this->cwd = \getcwd();
$this->cwd = (string) \getcwd();
}

/**
Expand All @@ -39,6 +39,8 @@ public function copyFilesIntoProject (string $directory) : void

/**
* Add the given config to the projects composer.json
*
* @param array<array-key, mixed> $config
*/
public function addToProjectComposerJson (array $config) : void
{
Expand All @@ -58,13 +60,14 @@ public function addToProjectComposerJson (array $config) : void
* If there are multiple lines matching, all will be replaced.
* If there are no lines matching, the call will just be appended.
*
*
* @param string $key The scripts key to update.
* @param string $key The scripts key to update.
* @param array<string, string> $scripts The scripts to replace.
*/
function updateProjectComposerJsonScripts (string $key, array $scripts) : void
public function updateProjectComposerJsonScripts (string $key, array $scripts) : void
{
$jsonContent = $this->readProjectComposerJson();
\assert(!isset($jsonContent["scripts"]) || \is_array($jsonContent["scripts"]));

$existingScripts = $jsonContent["scripts"][$key] ?? [];
// keep existing scripts
$result = [];
Expand Down Expand Up @@ -94,6 +97,9 @@ function updateProjectComposerJsonScripts (string $key, array $scripts) : void
}

/**
* Writes the given config to the project composer.json
*
* @param array<array-key, mixed> $config
*/
private function writeProjectComposerJson (array $config) : void
{
Expand All @@ -109,21 +115,26 @@ private function writeProjectComposerJson (array $config) : void
}

/**
* @return array<array-key, mixed>
*/
private function readProjectComposerJson () : array
{
$filePath = "{$this->cwd}/composer.json";

return \json_decode(
\file_get_contents($filePath),
$result = \json_decode(
(string) \file_get_contents($filePath),
true,
flags: \JSON_THROW_ON_ERROR
flags: \JSON_THROW_ON_ERROR,
);
\assert(\is_array($result));
return $result;
}


/**
* Runs a composer command in the project
*
* @param string[] $cmd
*/
public function runComposerInProject (array $cmd) : void
{
Expand All @@ -143,6 +154,8 @@ public function runComposerInProject (array $cmd) : void

/**
* Runs the given command in the project directory
*
* @param string[] $cmd
*/
public function runProcessInProject (array $cmd) : void
{
Expand Down
11 changes: 11 additions & 0 deletions vendor-bin/c-norm/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"require-dev": {
"ergebnis/composer-normalize": "^2.42",
"roave/security-advisories": "dev-latest"
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true
}
}
}
6 changes: 6 additions & 0 deletions vendor-bin/cs-fixer/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"require-dev": {
"21torr/php-cs-fixer": "^1.0.2",
"roave/security-advisories": "dev-latest"
}
}
21 changes: 21 additions & 0 deletions vendor-bin/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"require": {
"php": "^8.3"
},
"require-dev": {
"phpstan/extension-installer": "^1.3.1",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-doctrine": "^1.4",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-symfony": "^1.4",
"roave/security-advisories": "dev-latest",
"staabm/phpstan-todo-by": "^0.1.25"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
}
}

0 comments on commit 5e3f620

Please sign in to comment.