| | private const PER_PAGE = 100; |
| | |
| | - private $currentRepo; |
| | - private $git; |
| | - private $hash; |
| | + private array $currentRepo; |
| | + private Git $git; |
| | + private string $hash; |
| | |
| | public function __construct( |
 |
| | } |
| | |
| | - public function render() { |
| | + public function render(): void { |
| | $this->renderLayout( function() { |
| | - $main = $this->git->getMainBranch(); |
| | - $start = ''; |
| | - $count = 0; |
| | + $main = $this->git->getMainBranch(); |
| | |
| | if( !$main ) { |
 |
| | htmlspecialchars( $main['name'] ) . '</span></h2>'; |
| | echo '<div class="commit-list">'; |
| | - |
| | - $start = $this->hash !== '' ? $this->hash : $main['hash']; |
| | |
| | + $start = $this->hash !== '' ? $this->hash : $main['hash']; |
| | $commits = []; |
| | |
| | $this->git->history( |
| | $start, |
| | self::PER_PAGE, |
| | - function( $commit ) use ( &$commits ) { |
| | + function( array $commit ) use( &$commits ) { |
| | $commits[] = $commit; |
| | } |
| | ); |
| | |
| | - $count = count( $commits ); |
| | - $nav = $this->buildPagination( $main['hash'], $count ); |
| | + $nav = $this->buildPagination( $main['hash'], count( $commits ) ); |
| | |
| | $this->renderPagination( $nav ); |
| | |
| | foreach( $commits as $commit ) { |
| | $this->renderCommitRow( $commit ); |
| | } |
| | |
| | echo '</div>'; |
| | - |
| | $this->renderPagination( $nav ); |
| | } |
| | }, $this->currentRepo ); |
| | } |
| | |
| | - private function renderCommitRow( object $commit ) { |
| | - $msg = htmlspecialchars( explode( "\n", $commit->message )[0] ); |
| | - $url = $this->buildCommitUrl( $commit->sha ); |
| | + private function renderCommitRow( array $commit ): void { |
| | + $msg = htmlspecialchars( explode( "\n", $commit['message'] )[0] ); |
| | + $url = $this->buildCommitUrl( $commit['sha'] ); |
| | |
| | echo '<div class="commit-row">'; |
| | echo '<a href="' . $url . '" class="sha">' . |
| | - substr( $commit->sha, 0, 7 ) . '</a>'; |
| | + substr( $commit['sha'], 0, 7 ) . '</a>'; |
| | echo '<span class="message">' . $msg . '</span>'; |
| | - echo '<span class="meta">' . htmlspecialchars( $commit->author ) . |
| | - ' • ' . date( 'Y-m-d', $commit->date ) . '</span>'; |
| | + echo '<span class="meta">' . htmlspecialchars( $commit['author'] ) . |
| | + ' • ' . date( 'Y-m-d', $commit['date'] ) . '</span>'; |
| | echo '</div>'; |
| | } |
| | |
| | - private function renderPagination( array $nav ) { |
| | + private function renderPagination( array $nav ): void { |
| | $pages = $nav['pages']; |
| | $current = $nav['current']; |
| | $hasNext = $nav['hasNext']; |
| | - $hasAll = $nav['hasAll']; |
| | $hasPrev = $current > 1; |
| | $total = count( $pages ); |
| | |
| | if( $hasPrev || $hasNext ) { |
| | echo '<div class="pagination">'; |
| | |
| | if( $hasPrev ) { |
| | - $firstUrl = $this->buildPageUrl( $pages[0] ); |
| | - |
| | - echo '<a href="' . $firstUrl . '" class="page-link page-nav" ' . |
| | - 'aria-label="first">' . $this->svgArrow( 'first' ) . |
| | - '</a>'; |
| | - |
| | - $prevUrl = $this->buildPageUrl( $pages[$current - 2] ); |
| | + echo '<a href="' . $this->buildPageUrl( $pages[0] ) . |
| | + '" class="page-link page-nav" aria-label="first">' . |
| | + $this->svgArrow( 'first' ) . '</a>'; |
| | |
| | - echo '<a href="' . $prevUrl . '" class="page-link page-nav" ' . |
| | - 'aria-label="back">' . $this->svgArrow( 'back' ) . |
| | - '</a>'; |
| | + echo '<a href="' . $this->buildPageUrl( $pages[$current - 2] ) . |
| | + '" class="page-link page-nav" aria-label="back">' . |
| | + $this->svgArrow( 'back' ) . '</a>'; |
| | } else { |
| | echo '<span class="page-link page-nav page-nav-hidden" ' . |
 |
| | |
| | if( $hasNext ) { |
| | - $nextUrl = $this->buildPageUrl( $pages[$current] ); |
| | - $lastUrl = $this->buildPageUrl( $pages[$total - 1] ); |
| | - |
| | - echo '<a href="' . $nextUrl . '" class="page-link page-nav" ' . |
| | - 'aria-label="next">' . $this->svgArrow( 'next' ) . |
| | - '</a>'; |
| | + echo '<a href="' . $this->buildPageUrl( $pages[$current] ) . |
| | + '" class="page-link page-nav" aria-label="next">' . |
| | + $this->svgArrow( 'next' ) . '</a>'; |
| | |
| | - echo '<a href="' . $lastUrl . '" class="page-link page-nav" ' . |
| | - 'aria-label="last">' . $this->svgArrow( 'last' ) . |
| | - '</a>'; |
| | + echo '<a href="' . $this->buildPageUrl( $pages[$total - 1] ) . |
| | + '" class="page-link page-nav" aria-label="last">' . |
| | + $this->svgArrow( 'last' ) . '</a>'; |
| | } else { |
| | echo '<span class="page-link page-nav page-nav-hidden" ' . |
 |
| | |
| | $inner = $icons[$type] ?? ''; |
| | - $svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" ' . |
| | - 'fill="none" stroke="currentColor" stroke-width="2" ' . |
| | - 'stroke-linecap="round" stroke-linejoin="round" ' . |
| | - 'aria-label="' . $type . '" role="img">' . |
| | - '<title>' . $type . '</title>' . $inner . '</svg>'; |
| | |
| | - return $svg; |
| | + return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" ' . |
| | + 'fill="none" stroke="currentColor" stroke-width="2" ' . |
| | + 'stroke-linecap="round" stroke-linejoin="round" ' . |
| | + 'aria-label="' . $type . '" role="img">' . |
| | + '<title>' . $type . '</title>' . $inner . '</svg>'; |
| | } |
| | |
| | - private function renderPageNumbers( array $pages, int $current ) { |
| | + private function renderPageNumbers( array $pages, int $current ): void { |
| | $total = count( $pages ); |
| | - $start = $current - 4; |
| | + $start = max( 1, $current - 4 ); |
| | + $end = min( $total, $start + 9 ); |
| | $actual = 1; |
| | - $end = 0; |
| | - $sha = ''; |
| | - $url = ''; |
| | - |
| | - if( $start < 1 ) { |
| | - $start = 1; |
| | - } |
| | - |
| | - $end = $start + 9; |
| | - |
| | - if( $end > $total ) { |
| | - $end = $total; |
| | - $start = $end - 9; |
| | |
| | - if( $start < 1 ) { |
| | - $start = 1; |
| | - } |
| | + if( $end === $total ) { |
| | + $start = max( 1, $end - 9 ); |
| | } |
| | |
| | while( $actual <= $total ) { |
| | if( $actual >= $start && $actual <= $end ) { |
| | if( $actual === $current ) { |
| | echo '<span class="page-badge">' . $actual . '</span>'; |
| | } else { |
| | - $sha = $pages[$actual - 1]; |
| | - $url = $this->buildPageUrl( $sha ); |
| | - |
| | - echo '<a href="' . $url . '" class="page-link">' . $actual . '</a>'; |
| | + echo '<a href="' . $this->buildPageUrl( $pages[$actual - 1] ) . |
| | + '" class="page-link">' . $actual . '</a>'; |
| | } |
| | } |
 |
| | $found = false; |
| | $hitLimit = false; |
| | - $result = []; |
| | |
| | $this->git->history( |
| | $mainHash, |
| | PHP_INT_MAX, |
| | - function( $commit ) use ( |
| | + function( array $commit ) use( |
| | $target, |
| | &$pageHashes, |
 |
| | |
| | if( $commits % self::PER_PAGE === 0 ) { |
| | - $pageHashes[] = $commit->sha; |
| | + $pageHashes[] = $commit['sha']; |
| | } |
| | |
| | - if( $commit->sha === $target ) { |
| | + if( $commit['sha'] === $target ) { |
| | $currentPage = count( $pageHashes ); |
| | $found = true; |
 |
| | } |
| | ); |
| | - |
| | - $result['pages'] = $pageHashes; |
| | - $result['current'] = $currentPage; |
| | - $result['hasAll'] = !$hitLimit; |
| | - $result['hasNext'] = $count === self::PER_PAGE && |
| | - isset( $pageHashes[$currentPage] ); |
| | |
| | - return $result; |
| | + return [ |
| | + 'pages' => $pageHashes, |
| | + 'current' => $currentPage, |
| | + 'hasAll' => !$hitLimit, |
| | + 'hasNext' => $count === self::PER_PAGE && |
| | + isset( $pageHashes[$currentPage] ) |
| | + ]; |
| | } |
| | |
| | private function buildCommitUrl( string $targetHash ): string { |
| | - $builder = new UrlBuilder(); |
| | - $result = ''; |
| | - |
| | - $builder->withRepo( $this->currentRepo['safe_name'] ); |
| | - $builder->withAction( 'commit' ); |
| | - $builder->withHash( $targetHash ); |
| | - |
| | - $result = $builder->build(); |
| | - |
| | - return $result; |
| | + return (new UrlBuilder()) |
| | + ->withRepo( $this->currentRepo['safe_name'] ) |
| | + ->withAction( 'commit' ) |
| | + ->withHash( $targetHash ) |
| | + ->build(); |
| | } |
| | |
| | private function buildPageUrl( string $targetHash ): string { |
| | - $builder = new UrlBuilder(); |
| | - $result = ''; |
| | - |
| | - $builder->withRepo( $this->currentRepo['safe_name'] ); |
| | - $builder->withAction( 'commits' ); |
| | - $builder->withHash( $targetHash ); |
| | - |
| | - $result = $builder->build(); |
| | - |
| | - return $result; |
| | + return (new UrlBuilder()) |
| | + ->withRepo( $this->currentRepo['safe_name'] ) |
| | + ->withAction( 'commits' ) |
| | + ->withHash( $targetHash ) |
| | + ->build(); |
| | } |
| | } |