SyncCommand

Class
extends AbstractCommand
Final: Yes

Represents the command responsible for installing development scripts into `composer.json`.

Attributes
#[AsCommand]
$name : 'dev-tools:sync'
$description : 'Installs and synchronizes dev-tools scripts, GitHub Actions workflows, .editorconfig, and .gitattributes in the root project.'
$help : 'This command adds or updates dev-tools scripts in composer.json, copies reusable GitHub Actions workflows, ensures .editorconfig is present and up to date, ' . 'and manages .gitattributes export-ignore rules.'

Table of Contents

Properties

 : Filesystem

Methods

__construct()

Constructs a new AbstractCommand instance.

 : mixed
execute()

Executes the script installation block.

 : int
getAbsolutePath()

Computes the absolute path for a given relative or absolute path.

 : string
getConfigFile()

Determines the correct absolute path to a configuration file.

 : string
getCurrentWorkingDirectory()

Retrieves the current working directory of the application.

 : string
getDevToolsFile()

Resolves the absolute path to a file within the fast-forward/dev-tools package.

 : string
runCommand()

Configures and executes a registered console command by name.

 : int
runProcess()

Executes a given system process gracefully and outputs its buffer.

 : int
addRepositoryWikiGitSubmodule()

Ensures the repository wiki is added as a git submodule in .github/wiki.

 : void
copyDependabotConfig()

Installs the dependabot.yml configuration file in the .github directory if it does not exist.

 : void
copyEditorConfig()

Installs or updates the .editorconfig file in the root project directory.

 : void
copyGitHooks()

Copies git hooks from resources to .git/hooks for vendor synchronization.

 : void
createGitHubActionWorkflows()

Creates GitHub Actions workflow templates in the consumer repository.

 : void
getGitRepositoryUrl()

Retrieves the git remote origin URL for the current repository.

 : string
updateComposerJson()

Updates the root composer.json file with required scripts and extra configuration.

 : void
Properties

$filesystem

Protected Read-only
protected Filesystem $filesystem
Methods

__construct()

Public

Constructs a new AbstractCommand instance.

public __construct(Filesystem  $filesystem) : mixed
Parameters
$filesystem : Filesystem

Description

the filesystem utility to use

execute()

Protected

Executes the script installation block.

protected execute(InputInterface  $input, OutputInterface  $output) : int

Description

The method MUST leverage the ScriptsInstallerTrait to update the configuration. It SHALL return self::SUCCESS upon completion.

Parameters
$input : InputInterface

Description

the input interface

$output : OutputInterface

Description

the output interface

Return values
int

Description

the status code of the command

getAbsolutePath()

Protected

Computes the absolute path for a given relative or absolute path.

protected getAbsolutePath( string  $relativePath) : string

Description

This method MUST return the exact path if it is already absolute. If relative, it SHALL make it absolute relying on the current working directory.

Parameters
$relativePath : string

Description

the path to evaluate or resolve

Return values
string

Description

the resolved absolute path

getConfigFile()

Protected

Determines the correct absolute path to a configuration file.

protected getConfigFile( string  $filename[, bool  $force = false]) : string

Description

The method MUST attempt to resolve the configuration file locally in the working directory. If absent and not forced, it SHALL provide the default equivalent from the package itself.

Parameters
$filename : string

Description

the name of the configuration file

$force : bool = false

Description

determines whether to bypass fallback and forcefully return the local file path

Return values
string

Description

the resolved absolute path to the configuration file

getCurrentWorkingDirectory()

Protected

Retrieves the current working directory of the application.

protected getCurrentWorkingDirectory() : string

Description

The method MUST return the initial working directory defined by the application. If not available, it SHALL fall back to the safe current working directory.

Return values
string

Description

the absolute path to the current working directory

getDevToolsFile()

Protected

Resolves the absolute path to a file within the fast-forward/dev-tools package.

protected getDevToolsFile( string  $filename) : string

Description

This method uses Composer's InstalledVersions to determine the installation path of the fast-forward/dev-tools package and returns the absolute path to the given filename within it. It is used as a fallback when a configuration file is not found in the project root.

Parameters
$filename : string

Description

the name of the file to resolve within the dev-tools package

Return values
string

Description

the absolute path to the file inside the dev-tools package

runCommand()

Protected

Configures and executes a registered console command by name.

protected runCommand( string  $command, OutputInterface  $output) : int

Description

The method MUST run the specified command with the provided input and output interfaces.

Parameters
$command : string

Description

the commandline name of the command to execute

$output : OutputInterface

Description

the interface for buffering output

Return values
int

Description

the status code resulting from the dispatched command

runProcess()

Protected

Executes a given system process gracefully and outputs its buffer.

protected runProcess(Process  $command, OutputInterface  $output[, bool  $tty = true]) : int

Description

The method MUST execute the provided command ensuring the output is channeled to the OutputInterface. It SHOULD leverage TTY if supported. If the process fails, it MUST return self::FAILURE; otherwise, it SHALL return self::SUCCESS.

Parameters
$command : Process

Description

the configured process instance to run

$output : OutputInterface

Description

the output interface to log warnings or results

$tty : bool = true
Return values
int

Description

the status code of the command execution

addRepositoryWikiGitSubmodule()

Private

Ensures the repository wiki is added as a git submodule in .github/wiki.

private addRepositoryWikiGitSubmodule() : void

Description

This method checks if the .github/wiki directory exists. If not, it adds the repository's wiki as a submodule using the remote origin URL, replacing .git with .wiki.git. This allows automated documentation and wiki updates.

copyDependabotConfig()

Private

Installs the dependabot.yml configuration file in the .github directory if it does not exist.

private copyDependabotConfig() : void

Description

This method copies the dependabot.yml from the package resources to .github/dependabot.yml if it is not already present.

copyEditorConfig()

Private

Installs or updates the .editorconfig file in the root project directory.

private copyEditorConfig() : void

Description

This method copies the .editorconfig from the package resources to the project root, always overwriting to ensure it is up to date.

copyGitHooks()

Private

Copies git hooks from resources to .git/hooks for vendor synchronization.

private copyGitHooks(OutputInterface  $output) : void

Description

This method copies post-checkout and post-merge hooks from the package resources to .git/hooks, ensuring vendor dependencies stay synchronized when switching branches.

Parameters
$output : OutputInterface

Description

the output interface

createGitHubActionWorkflows()

Private

Creates GitHub Actions workflow templates in the consumer repository.

private createGitHubActionWorkflows() : void

Description

This method copies all .yml workflow templates from resources/github-actions to .github/workflows, unless the target file already exists. It is intended to provide reusable workflow_call templates for consumers.

getGitRepositoryUrl()

Private

Retrieves the git remote origin URL for the current repository.

private getGitRepositoryUrl() : string

Description

This method runs 'git config --get remote.origin.url' and returns the trimmed output.

Return values
string

Description

The remote origin URL of the repository

updateComposerJson()

Private

Updates the root composer.json file with required scripts and extra configuration.

private updateComposerJson() : void

Description

This method adds or updates the dev-tools scripts and extra configuration for tools like grumphp. It does nothing if the composer.json file does not exist.