Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
"name": "picamator/transfer-object",
"description": "A modern Symfony-compatible Transfer Object Generator with property hooks, FixedArray, and asymmetric visibilities.",
"keywords": [
"transfer-object",
"data-transfer-object",
"transfer-object-generator",
"data-transfer-object-generator",
"dto",
"dto-generator",
"definition-generator",
"symfony",
"symfony-console",
"generator",
"automation"
"symfony",
"symfony-console"
],
"license": "MIT",
"authors": [
Expand Down Expand Up @@ -78,25 +75,28 @@
},
"prefer-stable": true,
"scripts": {
"phpunit": "./vendor/bin/phpunit --no-progress",
"phpunit-group": "./vendor/bin/phpunit --testdox --group",
"phpstan": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --memory-limit=512M",
"transfer-generate": "php ./bin/transfer-generate",
"transfer-generate-bulk": "php ./bin/transfer-generate-bulk",
"definition-generate": "php ./bin/definition-generate",
"captainhook": "./vendor/bin/captainhook",
"phpcs": "./vendor/bin/phpcs -q --colors",
"phpcbf": "./vendor/bin/phpcbf -q --colors"
"captainhook": "captainhook",
"definition-generate": "@php ./bin/definition-generate",
"phpcbf": "phpcbf -q --colors",
"phpcs": "phpcs -q --colors",
"phpstan": "phpstan analyse -c phpstan.neon --no-progress --memory-limit=512M",
"phpunit": "phpunit --no-progress",
"phpunit-group": "@phpunit --testdox --group",
"transfer-generate": "@php ./bin/transfer-generate",
"transfer-generate-bulk": "@php ./bin/transfer-generate-bulk"
},
"scripts-aliases": {
"phpunit": ["test"]
},
"scripts-descriptions": {
"captainhook": "Manage and execute Git hooks.",
"definition-generate": "Create Transfer Object definition files based on JSON blueprints.",
"phpcbf": "Automatically fix coding style issues with PHP Code Beautifier and Fixer.",
"phpcs": "Analyze code style using PHP CodeSniffer.",
"phpstan": "Perform static code analysis using PHPStan.",
"phpunit": "Run unit and integration tests.",
"phpunit-group": "Run unit and integration tests assigned to the group.",
"phpstan": "Perform static code analysis using PHPStan.",
"transfer-generate": "Generate Transfer Objects from YML definition templates.",
"transfer-generate-bulk": "Generate Transfer Objects based on configuration list.",
"definition-generate": "Create Transfer Object definition files based on JSON blueprints.",
"captainhook": "Manage and execute Git hooks.",
"phpcs": "Analyze code style using PHP CodeSniffer.",
"phpcbf": "Automatically fix coding style issues with PHP Code Beautifier and Fixer."
"transfer-generate-bulk": "Generate Transfer Objects based on configuration list."
}
}
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docker/bash/sdk-autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ _docker_sdk_autocomplete() {
prev="${COMP_WORDS[COMP_CWORD-1]}"

# define the main commands for docker/sdk
opts="build start stop cli composer phpstan phpunit phpunit-group phpcs phpcbf hook-install hook to-generate to-generate-bulk df-generate"
opts="install build start stop cli composer phpstan phpunit phpunit-group phpcs phpcbf hook-install hook to-generate to-generate-bulk df-generate"

case "${prev}" in
composer)
# define subcommands for 'composer'
COMPREPLY=( $(compgen -W "install update why phpunit phpunit-group phpstan transfer-generate transfer-generate-bulk definition-generate captainhook phpcs phpcbf list" -- "${cur}") )
COMPREPLY=( $(compgen -W "install update why test phpunit phpunit-group phpstan transfer-generate transfer-generate-bulk definition-generate captainhook phpcs phpcbf list" -- "${cur}") )
return 0
;;
hook)
Expand Down
2 changes: 1 addition & 1 deletion docker/php/bash/composer-autocomplete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _composer_autocomplete() {
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="install update why phpunit phpunit-group phpstan transfer-generate transfer-generate-bulk definition-generate captainhook phpcs phpcbf list"
opts="install update why test phpunit phpunit-group phpstan transfer-generate transfer-generate-bulk definition-generate captainhook phpcs phpcbf list"

if [[ ${prev} == "composer" ]]; then
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
Expand Down
94 changes: 43 additions & 51 deletions docker/sdk
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ function wrap_in_yellow() {
echo -e "\e[33m$1\e[0m"
}

# function to print a command/option with its description
function print_command() {
printf " %-35s %s\n" "$(wrap_in_yellow "$1")" "$2"
}

# function to print an example with its description
function print_example() {
printf " %-40s %s\n" "$(wrap_in_yellow "$1")" "$2"
}

# function to display usage
function show_usage() {
wrap_in_green "==================================="
Expand All @@ -19,30 +29,31 @@ function show_usage() {
wrap_in_yellow "$0 [-x] [-p] <command> [args]"
echo
echo "Options:"
echo -e " $(wrap_in_yellow "-x") Enable Xdebug with debug + coverage mode when starting containers"
echo -e " $(wrap_in_yellow "-p") Enable Xdebug with profiler mode when starting containers"
print_command "-x" "Enable Xdebug (debug, coverage)"
print_command "-p" "Enable Xdebug (profiler)"
echo
echo "Commands:"
echo -e " $(wrap_in_yellow "build") Build Docker containers"
echo -e " $(wrap_in_yellow "start") Start Docker containers (honors -x / -p)"
echo -e " $(wrap_in_yellow "stop") Stop Docker containers"
echo -e " $(wrap_in_yellow "cli") Open container shell or execute the PHP script when provided as an argument"
echo -e " $(wrap_in_yellow "composer <command>") Run composer command"
echo -e " $(wrap_in_yellow "phpstan") Run PHPStan"
echo -e " $(wrap_in_yellow "phpunit") Run all PHPUnit tests or concrete test case when full qualified name provided as an argument"
echo -e " $(wrap_in_yellow "phpunit-group <group>") Run PHPUnit tests assigned to the group"
echo -e " $(wrap_in_yellow "phpcs") Run PHP CodeSniffer"
echo -e " $(wrap_in_yellow "phpcbf") Run PHP Code Beautifier and Fixer"
echo -e " $(wrap_in_yellow "hook-install") Install CaptainHook"
echo -e " $(wrap_in_yellow "hook <command>") Run CaptainHook command"
echo -e " $(wrap_in_yellow "to-generate") Generate internal transfer objects or externals when configuration path provided as an argument"
echo -e " $(wrap_in_yellow "to-generate-bulk") Generate bulk internal transfer objects or externals when configuration path provided as an argument"
echo -e " $(wrap_in_yellow "df-generate") Generate definition"
print_command "install" "Install development environment"
print_command "build" "Build Docker containers"
print_command "start" "Start Docker containers (honors -x / -p)"
print_command "stop" "Stop Docker containers"
print_command "cli [script]" "Open container shell or execute PHP script"
print_command "composer <cmd>" "Run composer command"
print_command "phpstan" "Run PHPStan"
print_command "phpunit [filter]" "Run PHPUnit tests"
print_command "phpunit-group <g>" "Run PHPUnit tests by group"
print_command "phpcs" "Run PHP CodeSniffer"
print_command "phpcbf" "Run PHP Code Beautifier and Fixer"
print_command "hook-install" "Install CaptainHook"
print_command "hook <cmd>" "Run CaptainHook command"
print_command "to-generate [c]" "Generate transfer objects"
print_command "to-generate-bulk [b]" "Generate bulk transfer objects"
print_command "df-generate" "Generate definitions"
echo
echo "Examples:"
echo -e " $(wrap_in_yellow "$0 -x start") Start containers with Xdebug (debug + coverage)"
echo -e " $(wrap_in_yellow "$0 -p start") Start containers with Xdebug profiler"
echo -e " $(wrap_in_yellow "$0 composer install") Run composer install inside container"
print_example "$0 -x start" "Start containers (Xdebug: debug, coverage)"
print_example "$0 -p start" "Start containers (Xdebug: profiler)"
print_example "$0 composer install" "Run composer install inside container"
}

# vars
Expand Down Expand Up @@ -70,6 +81,9 @@ shift $((OPTIND -1))

# arguments
case $1 in
install)
$0 build && $0 start && $0 composer install
;;
build)
USER_ID=$(id -u) GROUP_ID=$(id -g) docker compose build
;;
Expand All @@ -84,41 +98,27 @@ case $1 in
docker compose stop
;;
cli)
if [ -n "$5" ]; then
$DOCKER_EXEC php "$2" "$3" "$4" "$5"
elif [ -n "$4" ]; then
$DOCKER_EXEC php "$2" "$3" "$4"
elif [ -n "$3" ]; then
$DOCKER_EXEC php "$2" "$3"
elif [ -n "$2" ]; then
$DOCKER_EXEC php $2
else
if [ -z "$2" ]; then
$DOCKER_EXEC bash
else
$DOCKER_EXEC php "${@:2}"
fi
;;
composer)
if [ -n "$5" ]; then
$DOCKER_EXEC composer "$2" "$3" "$4" "$5"
elif [ -n "$4" ]; then
$DOCKER_EXEC composer "$2" "$3" "$4"
elif [ -n "$3" ]; then
$DOCKER_EXEC composer "$2" "$3"
else
$DOCKER_EXEC composer "$2"
fi
$DOCKER_EXEC composer "${@:2}"
;;
phpstan)
$DOCKER_EXEC composer phpstan
;;
phpunit)
if [ -n "$2" ]; then
$DOCKER_EXEC composer phpunit -- --filter $2
$DOCKER_EXEC composer phpunit -- --filter "$2"
else
$DOCKER_EXEC composer phpunit
fi
;;
phpunit-group)
$DOCKER_EXEC composer phpunit-group $2
$DOCKER_EXEC composer phpunit-group "$2"
;;
phpcs)
$DOCKER_EXEC composer phpcs
Expand All @@ -130,21 +130,13 @@ case $1 in
$DOCKER_EXEC composer captainhook install --only-enabled --run-mode=docker --run-exec="docker exec -i $DOCKER_CONTAINER_NAME"
;;
hook)
$DOCKER_EXEC composer captainhook $2
$DOCKER_EXEC composer captainhook "${@:2}"
;;
to-generate)
if [ -n "$2" ]; then
$DOCKER_EXEC composer transfer-generate -- -c $2 -v
else
$DOCKER_EXEC composer transfer-generate -- -c ./config/generator.config.yml -v
fi
$DOCKER_EXEC composer transfer-generate -- -c "${2:-./config/generator.config.yml}" -v
;;
to-generate-bulk)
if [ -n "$2" ]; then
$DOCKER_EXEC composer transfer-generate-bulk -- -b $2
else
$DOCKER_EXEC composer transfer-generate-bulk -- -b ./var/config/config.list.txt
fi
$DOCKER_EXEC composer transfer-generate-bulk -- -b "${2:-./var/config/config.list.txt}"
;;
df-generate)
$DOCKER_EXEC composer definition-generate
Expand Down
15 changes: 11 additions & 4 deletions src/Shared/Filesystem/FileReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ private function assertEndOfFile($file, string $filename, int $fileLine): void
*/
private function getFile(string $filename)
{
if (!$this->fileExists($filename)) {
throw new FileReaderException(
sprintf('File "%s" does not exist.', $filename),
);
}

$file = $this->fopen($filename);
if ($file === false) {
throw new FileReaderException(
Expand All @@ -87,13 +93,14 @@ private function getFile(string $filename)
*/
protected function fopen(string $filename)
{
if (!file_exists($filename)) {
return false;
}

return fopen($filename, 'r');
}

protected function fileExists(string $filename): bool
{
return file_exists($filename);
}

/**
* @param resource $file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,19 @@ private function getProjectRoot(): string
return $this->projectRootCache = $projectRoot;
}

protected function getWorkingDir(): string
private function getWorkingDir(): string
{
return getcwd() ?: '';
return $this->getcwd() ?: '';
}

protected function getEnvironment(): string
protected function getcwd(): false|string
{
$envValue = getenv(static::ENVIRONMENT_KEY);
return getcwd();
}

private function getEnvironment(): string
{
$envValue = $this->getenv(static::ENVIRONMENT_KEY);
if (!is_string($envValue)) {
return '';
}
Expand All @@ -54,6 +59,14 @@ protected function getEnvironment(): string
|> $this->rtrimPath(...);
}

/**
* @return array<int, string>|false|string
*/
protected function getenv(string $name): array|false|string
{
return getenv($name);
}

private function rtrimPath(string $path): string
{
return rtrim($path, '\/');
Expand Down
Loading