bouiboui\Tissue\GithubIssue::formatTable PHP Method

formatTable() private static method

Formats the issue's table
private static formatTable ( $code, $severity ) : string
$code
$severity
return string
    private static function formatTable($code, $severity)
    {
        $displayCode = null !== $code;
        $displaySeverity = null !== $severity;
        $tableTitle = '';
        $tableContents = '';
        $tableDivider = '---';
        if ($displayCode && $displaySeverity) {
            $tableTitle = 'Code | Severity';
            $tableDivider = '--- | ---';
            $tableContents = $code . ' | ' . $severity;
        } else {
            if ($displayCode) {
                $tableTitle = 'Code';
                $tableContents = $code;
            } else {
                if ($displaySeverity) {
                    $tableTitle = 'Severity';
                    $tableContents = $severity;
                }
            }
        }
        return '| ' . $tableTitle . ' |' . PHP_EOL . '| ' . $tableDivider . ' |' . PHP_EOL . '| ' . $tableContents . ' |';
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * GithubIssue constructor.
  * Internally formats the Github issue title and message
  * @param string $message
  * @param int $code
  * @param int $severity
  * @param string $path
  * @param int $lineno
  * @param string $trace
  */
 public function __construct($message = null, $code = null, $severity = null, $path = null, $lineno = null, $trace = null)
 {
     // Default message
     if (null === $message) {
         $message = 'An error occured.';
     }
     // Format the title under 50 characters
     $this->title = GithubIssue::formatTitle($path, $lineno, $message);
     // Only display a two-parent-directories-deep path, for readability
     $shortPath = GithubIssue::formatPath($path);
     $bodyContents = [];
     // Head table (Code and Severity)
     if (null !== $code || null !== $severity) {
         $bodyContents[] = GithubIssue::formatTable($code, $severity);
     }
     // $path:$line
     if (null !== $path) {
         $pathText = '**Path**' . PHP_EOL . $shortPath;
         if (null !== $lineno) {
             $pathText .= ':**' . $lineno . '**';
         }
         $bodyContents[] = $pathText;
     }
     if (null !== $message) {
         $bodyContents[] = '**Message**' . PHP_EOL . $message;
     }
     if (null !== $trace) {
         $bodyContents[] = '**Stack trace**' . PHP_EOL . '```' . PHP_EOL . $trace . PHP_EOL . '```';
     }
     // Format the body
     $this->body = GithubIssue::formatBody($bodyContents);
 }