Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Reverts extension check

Author Dave Jarvis <email>
Date 2026-02-16 15:20:36 GMT-0800
Commit 8b0e5855c2ae4c36510b1b36d8873da1967e5cce
Parent 36ab3ab
Delta 1 line added, 26 lines removed, 25-line decrease
File.php
];
- 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 );
}
}