/** * Process the copyright tags. * * @param int $commentStart The position in the stack where * the comment started. * * @return void */ protected function processCopyrights($commentStart) { $copyrights = $this->commentParser->getCopyrights(); foreach ($copyrights as $copyright) { $errorPos = $commentStart + $copyright->getLine(); $content = $copyright->getContent(); if ($content !== '') { $matches = array(); if (preg_match('/^.*?([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) { // Check earliest-latest year order. if ($matches[3] !== '') { if ($matches[3] !== '-') { $error = 'A hyphen must be used between the earliest and latest year'; $this->currentFile->addError($error, $errorPos, 'CopyrightHyphen'); } if ($matches[4] !== '' && $matches[4] < $matches[1]) { $error = "Invalid year span \"{$matches['1']}{$matches['3']}{$matches['4']}\" found; consider \"{$matches['4']}-{$matches['1']}\" instead"; $this->currentFile->addWarning($error, $errorPos, 'InvalidCopyright'); } } } else { $error = '@copyright tag must contain a year and the name of the copyright holder'; $this->currentFile->addError($error, $errorPos, 'EmptyCopyright'); } } else { $error = '@copyright tag must contain a year and the name of the copyright holder'; $this->currentFile->addError($error, $errorPos, 'EmptyCopyright'); } //end if } //end if }
/** * Process the copyright tags. * * @param int $commentStart The position in the stack where * the comment started. * * @return void */ protected function processCopyrights($commentStart) { $copyrights = $this->commentParser->getCopyrights(); /** @var PHP_CodeSniffer_CommentParser_SingleElement $copyright */ foreach ($copyrights as $copyright) { $errorPos = $commentStart + $copyright->getLine(); $content = $copyright->getContent(); if ($content !== '') { $matches = array(); if (preg_match('~^.*?(\\d{4})(?:(.)(\\d{4}))? (.+)$~', $content, $matches) !== 0) { // Check earliest-latest year order. if ($matches[2] > '') { if ($matches[2] != '-') { $error = 'A hyphen must be used between the earliest and latest year'; $this->currentFile->addError($error, $errorPos, 'CopyrightHyphen'); } if (0 < $matches[3] && $matches[3] < $matches[1]) { $error = "Invalid year span \"{$matches['1']}{$matches['2']}{$matches['3']}\" found; consider \"{$matches['3']}-{$matches['1']}\" instead"; $this->currentFile->addWarning($error, $errorPos, 'InvalidCopyright'); } } } else { $error = '@copyright tag must contain a year and the name of the copyright holder'; $this->currentFile->addError($error, $errorPos, 'EmptyCopyright'); } } else { $error = '@copyright tag must contain a year and the name of the copyright holder'; $this->currentFile->addError($error, $errorPos, 'EmptyCopyright'); } } }