diff --git a/.gitignore b/.gitignore index d8a7996..427edf4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ composer.lock vendor/ +docs/ diff --git a/README.md b/README.md index 31c1a4c..9aceec9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ It should allow for the image to be displayed in a browser or even a terminal (y ## Why -Why not? But seriously, this doesn't make any sense, you should never use it in any circumstance whatsoever! The idea for this terrible endeavour came from [a video by Dylan O'Donnell](https://youtube.com). +Why not? But seriously, this doesn't make any sense, you should never use it in any circumstance whatsoever! ## Usage diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 0000000..895e98d --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,19 @@ + + + + docs/api + docs/cache + + + + + src + + + + diff --git a/src/Fits.php b/src/Fits.php index 5e51584..368438b 100644 --- a/src/Fits.php +++ b/src/Fits.php @@ -19,6 +19,8 @@ class Fits public readonly string $imageBlob; /** + * Construct a Fits object + * @param string $path The full path to the FITS file * @throws InvalidFits, InvalidPath * @todo Check path for reading/writing errors */ @@ -36,6 +38,7 @@ class Fits } $this->headerBlock = $this->extractHeader(); + $this->fitsHeader = new FitsHeader($this->headerBlock); $this->imageBlob = $this->extractImageBlob(); } @@ -67,6 +70,7 @@ class Fits */ private function extractHeader(): string { + $end = strpos($this->contents, 'END'); // Determine minimum integer number of blocks including 'END' position $headerEnd = (($end - ($end % 2880)) / 2880 + 1) * 2880; diff --git a/src/FitsHeader.php b/src/FitsHeader.php index 64a08b8..3fefac3 100644 --- a/src/FitsHeader.php +++ b/src/FitsHeader.php @@ -45,8 +45,10 @@ class FitsHeader foreach ($filtered as $record) { $splitByComment = explode('/', $record); - $comment = isset($splitByComment[1]) ? $splitByComment[1] : null; - [$name, $value] = explode('=', $splitByComment[0]); + $comment = $splitByComment[1] ?? null; + $keyVal = explode('=', $splitByComment[0]); + $name = $keyVal[0]; + $value = $keyVal[1] ?? ''; $keywords[] = new Keyword( name : $name, @@ -72,7 +74,7 @@ class FitsHeader return $keywordsString . $blanks; } /** - * Retrieve a Keyword object base on key name + * Retrieve a Keyword object based on key name */ public function keyword(string $key): ?Keyword { diff --git a/src/Keyword.php b/src/Keyword.php index a84a4ba..b065680 100644 --- a/src/Keyword.php +++ b/src/Keyword.php @@ -12,7 +12,7 @@ readonly class Keyword { public function __construct( public string $name, - public string $value, + public ?string $value, public ?string $comment, ) {} diff --git a/tests/FitsHeaderTest.php b/tests/FitsHeaderTest.php new file mode 100644 index 0000000..57af8fe --- /dev/null +++ b/tests/FitsHeaderTest.php @@ -0,0 +1,24 @@ +headerBlock); + + $this->assertSame( + trim($header->getKeywordValue('BITPIX')), + '16' + ); + $this->assertSame( + trim($header->getKeywordValue('NAXIS')), + '3' + ); + } +} + diff --git a/tests/FitsTest.php b/tests/FitsTest.php new file mode 100644 index 0000000..d413ba6 --- /dev/null +++ b/tests/FitsTest.php @@ -0,0 +1,16 @@ +assertTrue($fits->validate()); + } +} + diff --git a/tests/test_orion.fit b/tests/test_orion.fit new file mode 100644 index 0000000..4433c96 Binary files /dev/null and b/tests/test_orion.fit differ