Final Class Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand
| Inheritance | Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand » Symfony\Component\Console\Command\Command |
|---|
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| configure() | Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand | |
| execute() | Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand | |
| getAppRootDir() | Use this method to get a root directory of the tool. | Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand |
| getIO() | Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand | |
| initialize() | Yiisoft\YiiDevTool\App\Command\Stats\ContributorsCommand |
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 ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
| $output | \Symfony\Component\Console\Output\OutputInterface | |
protected function execute(InputInterface $input, OutputInterface $output)
{
$since = $input->getOption('since');
$sinceCommand = '';
if (!empty($since)) {
$sinceCommand = " --since=$since";
}
$this->initPackageList();
$installedPackages = $this
->getPackageList()
->getInstalledAndEnabledPackages();
$contributors = [];
foreach ($installedPackages as $installedPackage) {
$git = $installedPackage
->getGitWorkingCopy()
->getWrapper();
$out = $git->git("shortlog -s -e --group=author --group=trailer:co-authored-by$sinceCommand HEAD", $installedPackage->getPath());
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\YiiDevTool\App\Component\Console\OutputManager getIO ( ) |
protected function getIO(): OutputManager
{
if ($this->io === null) {
throw new RuntimeException('IO is not initialized.');
}
return $this->io;
}
| protected mixed initialize ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
| $output | \Symfony\Component\Console\Output\OutputInterface | |
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->io = new OutputManager(new YiiDevToolStyle($input, $output));
}
Signup or Login in order to comment.