| | ]; |
| | |
| | - private const TEXT_FILENAMES = [ |
| | - 'Containerfile', 'Dockerfile', 'Makefile', 'Jenkinsfile' |
| | - ]; |
| | - |
| | - private const TEXT_EXTENSIONS = [ |
| | - 'php', 'phtml', 'php8', 'php7', 'c', 'h', 'cpp', 'hpp', 'cc', 'cxx', |
| | - 'cs', 'csx', 'java', 'kt', 'kts', 'scala', 'sc', 'groovy', 'gvy', 'js', |
| | - 'jsx', 'mjs', 'ts', 'tsx', 'dart', 'swift', 'go', 'rs', 'py', 'pyw', |
| | - 'rb', 'erb', 'pl', 'pm', 't', 'lua', 'sh', 'bash', 'zsh', 'ps1', |
| | - 'psm1', 'psd1', 'bat', 'cmd', 'md', 'markdown', 'rmd', 'r', 'xml', |
| | - 'svg', 'html', 'htm', 'css', 'json', 'lock', 'sql', 'yaml', 'yml', |
| | - 'gradle', 'tex', 'sty', 'cls', 'ltx', 'properties', 'prop', 'ini', |
| | - 'cfg', 'conf', 'toml', 'mk', 'mak', 'diff', 'patch' |
| | - ]; |
| | - |
| | private string $name; |
| | private string $sha; |
 |
| | $this->isArchiveFile( $filename ) => self::CAT_ARCHIVE, |
| | str_contains( $this->mediaType, 'compressed' ) => self::CAT_ARCHIVE, |
| | - $this->isTextFile( $filename ) => self::CAT_TEXT, |
| | default => self::CAT_BINARY, |
| | }; |
| | } |
| | |
| | private function detectBinary(): bool { |
| | return $this->mediaType !== 'application/x-empty' |
| | - && !str_starts_with( $this->mediaType, 'text/' ) |
| | - && !$this->isTextFile( $this->name ); |
| | + && !str_starts_with( $this->mediaType, 'text/' ); |
| | } |
| | |
| | private function isArchiveFile( string $filename ): bool { |
| | return in_array( |
| | strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ), |
| | self::ARCHIVE_EXTENSIONS, |
| | true |
| | ); |
| | - } |
| | - |
| | - private function isTextFile( string $filename ): bool { |
| | - $basename = basename( $filename ); |
| | - $extension = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ); |
| | - |
| | - return in_array( $basename, self::TEXT_FILENAMES, true ) |
| | - || in_array( $extension, self::TEXT_EXTENSIONS, true ); |
| | } |
| | } |