Final Class Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand
| Inheritance | Yiisoft\ |
|---|
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| configure() | Yiisoft\ |
|
| execute() | Yiisoft\ |
|
| getAppRootDir() | Use this method to get a root directory of the tool. | Yiisoft\ |
| getIO() | Yiisoft\ |
|
| initialize() | Yiisoft\ |
Method Details
| protected mixed configure ( ) |
protected function configure()
{
$this
->setName('stats:contributors')
->addOption('since', null, InputArgument::OPTIONAL, 'Date and time to check contributors from YYYY-MM-DD.')
->setDescription('Displays contributors statistics');
parent::configure();
}
| protected mixed execute ( \ | ||
| $input | \ |
|
| $output | \ |
|
protected function execute(InputInterface $input, OutputInterface $output)
{
$since = (string) $input->getOption('since');
$this->initPackageList();
$installedPackages = $this
->getPackageList()
->getInstalledAndEnabledPackages();
$contributors = [];
foreach ($installedPackages as $installedPackage) {
$arguments = [
's' => true,
'e' => true,
'group' => ['author', 'trailer:co-authored-by'],
];
if (!empty($since)) {
$arguments['since'] = $since;
}
$out = $installedPackage
->getGitWorkingCopy()
->run('shortlog', [$arguments, 'HEAD']);
foreach (preg_split('~\R~' , $out, -1, PREG_SPLIT_NO_EMPTY) as $line) {
[$commits, $name] = preg_split('~\t~' , $line, -1, PREG_SPLIT_NO_EMPTY);
if (array_key_exists($name, $contributors)) {
$contributors[$name] += (int) $commits;
} else {
$contributors[$name] = (int) $commits;
}
}
}
arsort($contributors);
foreach ($contributors as $name => $commits) {
echo $name . "\n" ;
}
return Command::SUCCESS;
}
Use this method to get a root directory of the tool.
Commands and components can be moved as a result of refactoring, so you should not rely on their location in the file system.
| protected string getAppRootDir ( ) | ||
| return | string |
Path to the root directory of the tool WITH a TRAILING SLASH. |
|---|---|---|
protected function getAppRootDir(): string
{
return rtrim($this
->getApplication()
->getRootDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
| protected Yiisoft\ |
protected function getIO(): OutputManager
{
if ($this->io === null) {
throw new RuntimeException('IO is not initialized.');
}
return $this->io;
}
| protected mixed initialize ( \ | ||
| $input | \ |
|
| $output | \ |
|
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->io = new OutputManager(new YiiDevToolStyle($input, $output));
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.