Skip to content

Commit 871ef66

Browse files
refactor(cli): inject settings dependency into CLI classes
- Add Tiny_Settings dependency to Tiny_Cli and Tiny_Command constructors - Update method calls to include the new settings parameter - Improve code documentation with PHPDoc comments
1 parent 00c65a7 commit 871ef66

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/class-tiny-cli.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020

2121
class Tiny_Cli
2222
{
23+
/**
24+
* Tinify Settings
25+
*
26+
* @var Tiny_Settings
27+
*/
28+
private $tiny_settings;
2329

24-
public function __construct()
30+
public function __construct( $settings )
2531
{
32+
$this->tiny_settings = $settings;
2633

2734
// Only add CLI hooks when WP-CLI is available
2835
if (defined('WP_CLI') && WP_CLI) {
@@ -31,13 +38,23 @@ public function __construct()
3138
}
3239

3340
public function register_command() {
34-
$command_instance = new Tiny_Command();
41+
$command_instance = new Tiny_Command( $this->tiny_settings );
3542
WP_CLI::add_command('tiny', $command_instance);
3643
}
3744
}
3845

3946
class Tiny_Command
4047
{
48+
/**
49+
* Tinify Settings
50+
*
51+
* @var Tiny_Settings
52+
*/
53+
private $tiny_settings;
54+
55+
public function __construct( $settings ) {
56+
$this->tiny_settings = $settings;
57+
}
4158

4259
/**
4360
* Optimize will process images
@@ -109,7 +126,6 @@ private function get_unoptimized_attachments()
109126
return array();
110127
}
111128

112-
// PHP 5.6 compatible alternative to array_column
113129
$ids = array();
114130
foreach ($stats['available-for-optimization'] as $item) {
115131
if (isset($item['ID'])) {

0 commit comments

Comments
 (0)