Skip to content

Commit 64583fa

Browse files
Merge pull request #33 from kiwilan/develop
v3.0.08
2 parents 6f326b7 + 1f313ce commit 64583fa

File tree

11 files changed

+41
-52
lines changed

11 files changed

+41
-52
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "kiwilan/php-audio",
33
"description": "PHP package to parse and update audio files metadata, with `JamesHeinrich/getID3`.",
4-
"version": "3.0.07",
4+
"version": "3.0.08",
55
"keywords": [
66
"audio",
77
"php",

src/Audio.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ protected function __construct(
7474
protected AudioStat $stat,
7575
protected Id3Reader $reader,
7676
protected ?Id3Writer $writer = null,
77-
) {
78-
}
77+
) {}
7978

8079
public static function get(string $path): self
8180
{
@@ -304,6 +303,14 @@ public function getDuration(): ?float
304303
return $this->duration;
305304
}
306305

306+
/**
307+
* Get `duration` in human readable format: `00:00:00`.
308+
*/
309+
public function getDurationHumanReadable(): ?string
310+
{
311+
return gmdate('H:i:s', intval($this->duration));
312+
}
313+
307314
/**
308315
* Know if audio file is valid.
309316
*/

src/Models/AudioCore.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public function __construct(
2727
protected ?string $stik = null,
2828
protected bool $hasCover = false,
2929
protected ?AudioCoreCover $cover = null,
30-
) {
31-
}
30+
) {}
3231

3332
public function getTitle(): ?string
3433
{
@@ -456,11 +455,11 @@ public static function toAsf(AudioCore $core): Id3TagAsf
456455
public static function fromId3(?Id3AudioTagV1 $v1, ?Id3AudioTagV2 $v2): AudioCore
457456
{
458457
if (! $v1) {
459-
$v1 = new Id3AudioTagV1();
458+
$v1 = new Id3AudioTagV1;
460459
}
461460

462461
if (! $v2) {
463-
$v2 = new Id3AudioTagV2();
462+
$v2 = new Id3AudioTagV2;
464463
}
465464

466465
return new AudioCore(
@@ -646,12 +645,11 @@ public function __construct(
646645
protected ?string $picturetypeid = null,
647646
protected ?string $description = null,
648647
protected ?string $mime = null,
649-
) {
650-
}
648+
) {}
651649

652650
public static function make(string $pathOrData): self
653651
{
654-
$self = new self();
652+
$self = new self;
655653

656654
if (file_exists($pathOrData)) {
657655
$image = getimagesize($pathOrData);

src/Models/AudioCover.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static function make(?Id3Comments $comments): ?self
1818
return null;
1919
}
2020

21-
$self = new self();
21+
$self = new self;
2222

2323
$self->contents = $comments->picture()->data();
2424
$self->mimeType = $comments->picture()->image_mime();

src/Models/AudioMetadata.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ protected function __construct(
2222
protected ?string $channelMode = null,
2323
protected bool $lossless = false,
2424
protected ?float $compressionRatio = null,
25-
) {
26-
}
25+
) {}
2726

2827
public static function make(Audio $audio): self
2928
{

src/Models/AudioStat.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ protected function __construct(
2121
protected ?DateTime $modifiedAt = null,
2222
protected ?int $blockSize = null,
2323
protected ?int $numberOfBlocks = null,
24-
) {
25-
}
24+
) {}
2625

2726
public static function make(string $path): self
2827
{

src/Models/Id3Reader.php

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ protected function __construct(
3030
protected ?Id3TagsHtml $tags_html = null,
3131
protected ?float $bitrate = null,
3232
protected ?string $playtime_string = null,
33-
) {
34-
}
33+
) {}
3534

3635
public static function make(string $path): self
3736
{
38-
$self = new self(new getID3());
37+
$self = new self(new getID3);
3938

4039
$self->raw = $self->instance->analyze($path);
4140
$self->is_writable = $self->instance->is_writable($path);
@@ -260,8 +259,7 @@ protected function __construct(
260259
protected bool $lossless = false,
261260
protected ?string $encoder_options = null,
262261
protected ?float $compression_ratio = null,
263-
) {
264-
}
262+
) {}
265263

266264
public static function make(?array $metadata): ?self
267265
{
@@ -369,8 +367,7 @@ protected function __construct(
369367
protected ?float $resolution_x = null,
370368
protected ?float $resolution_y = null,
371369
protected ?float $frame_rate = null,
372-
) {
373-
}
370+
) {}
374371

375372
public static function make(?array $metadata): ?self
376373
{
@@ -429,8 +426,7 @@ protected function __construct(
429426
protected bool $lossless = false,
430427
protected ?string $encoder_options = null,
431428
protected ?float $compression_ratio = null,
432-
) {
433-
}
429+
) {}
434430

435431
public static function make(?array $metadata): ?self
436432
{
@@ -522,8 +518,7 @@ protected function __construct(
522518
protected ?Id3TagRiff $riff = null,
523519
protected ?Id3TagMatroska $matroska = null,
524520
protected ?Id3TagApe $ape = null,
525-
) {
526-
}
521+
) {}
527522

528523
public static function make(?array $metadata): ?self
529524
{
@@ -605,8 +600,7 @@ public function __construct(
605600
protected ?string $genre = null,
606601
protected ?string $comment = null,
607602
protected ?string $track_number = null,
608-
) {
609-
}
603+
) {}
610604

611605
public static function make(?array $metadata): ?self
612606
{
@@ -694,8 +688,7 @@ public function __construct(
694688
protected ?string $text = null,
695689
protected ?string $unsynchronised_lyric = null,
696690
protected ?string $language = null,
697-
) {
698-
}
691+
) {}
699692

700693
public static function make(?array $metadata): ?self
701694
{
@@ -826,8 +819,7 @@ class Id3Comments
826819
protected function __construct(
827820
protected ?string $language = null,
828821
protected ?Id3CommentsPicture $picture = null,
829-
) {
830-
}
822+
) {}
831823

832824
public static function make(?array $metadata): ?self
833825
{
@@ -862,8 +854,7 @@ protected function __construct(
862854
protected ?string $picturetype = null,
863855
protected ?string $description = null,
864856
protected ?int $datalength = null,
865-
) {
866-
}
857+
) {}
867858

868859
public static function make(?array $metadata): ?self
869860
{
@@ -942,8 +933,7 @@ public function __construct(
942933
protected ?string $lyrics = null,
943934
protected ?string $comment = null,
944935
protected ?string $stik = null,
945-
) {
946-
}
936+
) {}
947937

948938
public static function make(?array $metadata): ?self
949939
{
@@ -1110,8 +1100,7 @@ public function __construct(
11101100
protected ?string $track_number = null,
11111101
protected ?string $year = null,
11121102
protected ?string $encodingsettings = null,
1113-
) {
1114-
}
1103+
) {}
11151104

11161105
public static function make(?array $metadata): ?self
11171106
{
@@ -1217,8 +1206,7 @@ public function __construct(
12171206
protected ?string $compilation = null,
12181207
protected ?string $date = null,
12191208
protected ?string $tracknumber = null,
1220-
) {
1221-
}
1209+
) {}
12221210

12231211
public static function make(?array $metadata): ?self
12241212
{
@@ -1339,8 +1327,7 @@ public function __construct(
13391327
protected ?string $title = null,
13401328
protected ?string $product = null,
13411329
protected ?string $software = null,
1342-
) {
1343-
}
1330+
) {}
13441331

13451332
public static function make(?array $metadata): ?self
13461333
{
@@ -1427,8 +1414,7 @@ public function __construct(
14271414
protected ?string $date = null,
14281415
protected ?string $encoder = null,
14291416
protected ?string $duration = null,
1430-
) {
1431-
}
1417+
) {}
14321418

14331419
public static function make(?array $metadata): ?self
14341420
{
@@ -1575,8 +1561,7 @@ public function __construct(
15751561
protected ?string $podcastdesc = null,
15761562
protected ?string $language = null,
15771563
protected ?string $year = null,
1578-
) {
1579-
}
1564+
) {}
15801565

15811566
public static function make(?array $metadata): ?self
15821567
{
@@ -1734,8 +1719,7 @@ protected function __construct(
17341719
protected ?Id3TagRiff $riff = null,
17351720
protected ?Id3TagMatroska $matroska = null,
17361721
protected ?Id3TagApe $ape = null,
1737-
) {
1738-
}
1722+
) {}
17391723

17401724
public static function make(?array $metadata): ?self
17411725
{

src/Models/Id3Writer.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,14 @@ protected function __construct(
5151
protected Audio $audio,
5252
protected getid3_writetags $instance,
5353
protected AudioCore $core,
54-
) {
55-
}
54+
) {}
5655

5756
public static function make(Audio $audio): self
5857
{
5958
$self = new self(
6059
audio: $audio,
61-
instance: new getid3_writetags(),
62-
core: new AudioCore()
60+
instance: new getid3_writetags,
61+
core: new AudioCore
6362
);
6463

6564
return $self;

tests/AudioTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
expect($audio->getgetExtension())->toBe($extension);
154154
expect($audio->getFormat())->toBe($format);
155155
expect($audio->getDuration())->toBeFloat();
156+
expect($audio->getDurationHumanReadable())->toBe('00:00:11');
156157
expect($audio->getExtras())->toBeArray();
157158

158159
expect($audio)->toBeInstanceOf(Audio::class);

tests/AudiobookTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
expect($audio->getLyrics())->toBe('Lyrics');
3030
expect($audio->getStik())->toBe('Audiobook');
3131
expect($audio->getDuration())->toBe(11.00);
32+
expect($audio->getDurationHumanReadable())->toBe('00:00:11');
3233
expect($audio->getExtras())->toBeArray();
3334
expect($audio->toArray())->toBeArray();
3435

0 commit comments

Comments
 (0)