Completed
Push — develop ( 067cb9...77afdc )
by David
01:24
created
src/modules/food-kg/includes/Ingredients_Taxonomy_Recipe_Lift_Strategy.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -8,101 +8,101 @@
 block discarded – undo
8 8
 
9 9
 class Ingredients_Taxonomy_Recipe_Lift_Strategy implements Recipe_Lift_Strategy {
10 10
 
11
-	/**
12
-	 * @var Ingredients_Client
13
-	 */
14
-	private $ingredients_client;
15
-
16
-	/**
17
-	 * @var Notices
18
-	 */
19
-	private $notices;
20
-
21
-	/**
22
-	 * @var Content_Service
23
-	 */
24
-	private $content_service;
25
-
26
-	public function __construct( Ingredients_Client $ingredients_client, Notices $notices, Content_Service $content_service ) {
27
-		$this->ingredients_client = $ingredients_client;
28
-		$this->notices            = $notices;
29
-		$this->content_service    = $content_service;
30
-	}
31
-
32
-	public function run() {
33
-		$this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) );
34
-
35
-		/**
36
-		 * @var WP_Term[] $terms
37
-		 */
38
-		$terms                = get_terms(
39
-			array(
40
-				'taxonomy'   => 'wprm_ingredient',
41
-				'fields'     => 'all',
42
-				'hide_empty' => false,
43
-			)
44
-		);
45
-		$filtered_terms       = $this->terms_without_about_jsonld( $terms );
46
-		$filtered_terms_names = array_map( array( $this, 'term_name' ), $filtered_terms );
47
-		$ingredients          = $this->ingredients_client->ingredients( $filtered_terms_names );
48
-
49
-		foreach ( $ingredients as $key => $value ) {
50
-			$term = get_term_by( 'name', $key, 'wprm_ingredient' );
51
-			if ( ! isset( $term ) ) {
52
-				continue;
53
-			}
54
-
55
-			$this->content_service->set_about_jsonld(
56
-				Wordpress_Content_Id::create_term( $term->term_id ),
57
-				$value
58
-			);
59
-
60
-			/**
61
-			 * @@todo update notification with progress
62
-			 */
63
-		}
64
-
65
-		// Clean up caches.
66
-		do_action( 'wl_ttl_cache_cleaner__flush' );
67
-
68
-		/**
69
-		 * @@todo add notification that procedure is complete, with information about the number of processed items vs
70
-		 *   total items
71
-		 */
72
-		$count_terms        = count( $filtered_terms );
73
-		$count_lifted_terms = count( $ingredients );
74
-		/* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */
75
-		$this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) );
76
-	}
77
-
78
-	/**
79
-	 * @param $terms WP_Term[] An array of terms.
80
-	 *
81
-	 * @return WP_Term[]
82
-	 */
83
-	private function terms_without_about_jsonld( $terms ) {
84
-		return array_filter( $terms, array( $this, 'term_has_not_about_jsonld' ) );
85
-	}
86
-
87
-	/**
88
-	 * @param $term WP_Term
89
-	 *
90
-	 * @return bool true if the term has an about_jsonld otherwise false.
91
-	 */
92
-	private function term_has_not_about_jsonld( $term ) {
93
-		$about_jsonld = $this->content_service->get_about_jsonld(
94
-			Wordpress_Content_Id::create_term( $term->term_id )
95
-		);
96
-
97
-		return $about_jsonld === null;
98
-	}
99
-
100
-	/**
101
-	 * @param $term WP_Term
102
-	 *
103
-	 * @return string
104
-	 */
105
-	public function term_name( $term ) {
106
-		return $term->name;
107
-	}
11
+    /**
12
+     * @var Ingredients_Client
13
+     */
14
+    private $ingredients_client;
15
+
16
+    /**
17
+     * @var Notices
18
+     */
19
+    private $notices;
20
+
21
+    /**
22
+     * @var Content_Service
23
+     */
24
+    private $content_service;
25
+
26
+    public function __construct( Ingredients_Client $ingredients_client, Notices $notices, Content_Service $content_service ) {
27
+        $this->ingredients_client = $ingredients_client;
28
+        $this->notices            = $notices;
29
+        $this->content_service    = $content_service;
30
+    }
31
+
32
+    public function run() {
33
+        $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) );
34
+
35
+        /**
36
+         * @var WP_Term[] $terms
37
+         */
38
+        $terms                = get_terms(
39
+            array(
40
+                'taxonomy'   => 'wprm_ingredient',
41
+                'fields'     => 'all',
42
+                'hide_empty' => false,
43
+            )
44
+        );
45
+        $filtered_terms       = $this->terms_without_about_jsonld( $terms );
46
+        $filtered_terms_names = array_map( array( $this, 'term_name' ), $filtered_terms );
47
+        $ingredients          = $this->ingredients_client->ingredients( $filtered_terms_names );
48
+
49
+        foreach ( $ingredients as $key => $value ) {
50
+            $term = get_term_by( 'name', $key, 'wprm_ingredient' );
51
+            if ( ! isset( $term ) ) {
52
+                continue;
53
+            }
54
+
55
+            $this->content_service->set_about_jsonld(
56
+                Wordpress_Content_Id::create_term( $term->term_id ),
57
+                $value
58
+            );
59
+
60
+            /**
61
+             * @@todo update notification with progress
62
+             */
63
+        }
64
+
65
+        // Clean up caches.
66
+        do_action( 'wl_ttl_cache_cleaner__flush' );
67
+
68
+        /**
69
+         * @@todo add notification that procedure is complete, with information about the number of processed items vs
70
+         *   total items
71
+         */
72
+        $count_terms        = count( $filtered_terms );
73
+        $count_lifted_terms = count( $ingredients );
74
+        /* translators: 1: The number of lifted ingredients, 2: The total number of ingredients. */
75
+        $this->notices->queue( 'info', sprintf( __( 'WordLift detected WP Recipe Maker and, it lifted %1$d of %2$d ingredient(s).', 'wordlift' ), $count_lifted_terms, $count_terms ) );
76
+    }
77
+
78
+    /**
79
+     * @param $terms WP_Term[] An array of terms.
80
+     *
81
+     * @return WP_Term[]
82
+     */
83
+    private function terms_without_about_jsonld( $terms ) {
84
+        return array_filter( $terms, array( $this, 'term_has_not_about_jsonld' ) );
85
+    }
86
+
87
+    /**
88
+     * @param $term WP_Term
89
+     *
90
+     * @return bool true if the term has an about_jsonld otherwise false.
91
+     */
92
+    private function term_has_not_about_jsonld( $term ) {
93
+        $about_jsonld = $this->content_service->get_about_jsonld(
94
+            Wordpress_Content_Id::create_term( $term->term_id )
95
+        );
96
+
97
+        return $about_jsonld === null;
98
+    }
99
+
100
+    /**
101
+     * @param $term WP_Term
102
+     *
103
+     * @return string
104
+     */
105
+    public function term_name( $term ) {
106
+        return $term->name;
107
+    }
108 108
 }
Please login to merge, or discard this patch.
src/modules/food-kg/includes/Term_Entity/Food_Kg_Term_Entity_Runner.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -10,82 +10,82 @@
 block discarded – undo
10 10
 
11 11
 class Food_Kg_Term_Entity_Runner implements Runner {
12 12
 
13
-	/**
14
-	 * @var Food_Kg_Ingredients_Term_Store
15
-	 */
16
-	private $store;
17
-
18
-	/**
19
-	 * @var Content_Service
20
-	 */
21
-	private $content_service;
22
-
23
-	/**
24
-	 * @var Ingredients_Client
25
-	 */
26
-	private $ingredients_client;
27
-
28
-	public function __construct( Food_Kg_Ingredients_Term_Store $store, Content_Service $content_service, Ingredients_Client $ingredients_client ) {
29
-		$this->store              = $store;
30
-		$this->content_service    = $content_service;
31
-		$this->ingredients_client = $ingredients_client;
32
-	}
33
-
34
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
35
-	public function run( $last_id ) {
36
-
37
-		$items = $this->store->list_items( $last_id, 100 );
38
-		$names = array_column(
39
-			array_map(
40
-				function ( $item ) {
41
-					return (array) $item;
42
-				},
43
-				$items
44
-			),
45
-			'name'
46
-		);
47
-
48
-		$ingredients = $this->ingredients_client->ingredients( $names );
49
-
50
-		foreach ( $ingredients as $key => $value ) {
51
-			$term = get_term_by( 'name', $key, 'wprm_ingredient' );
52
-			if ( ! isset( $term ) || $this->term_has_about_jsonld( $term ) ) {
53
-				continue;
54
-			}
55
-
56
-			$content_id = Wordpress_Content_Id::create_term( $term->term_id );
57
-			$this->content_service->set_about_jsonld( $content_id, $value );
58
-		}
59
-
60
-		$count        = count( $items );
61
-		$last_item    = end( $items );
62
-		$last_item_id = ( isset( $last_item->term_id ) ? $last_item->term_id : null );
63
-
64
-		return array( $count, $last_item_id );
65
-	}
66
-
67
-	/**
68
-	 * Get the total number of posts to process.
69
-	 *
70
-	 * We only count published posts.
71
-	 *
72
-	 * @return int
73
-	 */
74
-	public function get_total() {
75
-		return $this->store->get_total();
76
-	}
77
-
78
-	/**
79
-	 * @param $term WP_Term
80
-	 *
81
-	 * @return bool true if the term has an about_jsonld otherwise false.
82
-	 */
83
-	private function term_has_about_jsonld( $term ) {
84
-		$about_jsonld = $this->content_service->get_about_jsonld(
85
-			Wordpress_Content_Id::create_term( $term->term_id )
86
-		);
87
-
88
-		return $about_jsonld !== null;
89
-	}
13
+    /**
14
+     * @var Food_Kg_Ingredients_Term_Store
15
+     */
16
+    private $store;
17
+
18
+    /**
19
+     * @var Content_Service
20
+     */
21
+    private $content_service;
22
+
23
+    /**
24
+     * @var Ingredients_Client
25
+     */
26
+    private $ingredients_client;
27
+
28
+    public function __construct( Food_Kg_Ingredients_Term_Store $store, Content_Service $content_service, Ingredients_Client $ingredients_client ) {
29
+        $this->store              = $store;
30
+        $this->content_service    = $content_service;
31
+        $this->ingredients_client = $ingredients_client;
32
+    }
33
+
34
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
35
+    public function run( $last_id ) {
36
+
37
+        $items = $this->store->list_items( $last_id, 100 );
38
+        $names = array_column(
39
+            array_map(
40
+                function ( $item ) {
41
+                    return (array) $item;
42
+                },
43
+                $items
44
+            ),
45
+            'name'
46
+        );
47
+
48
+        $ingredients = $this->ingredients_client->ingredients( $names );
49
+
50
+        foreach ( $ingredients as $key => $value ) {
51
+            $term = get_term_by( 'name', $key, 'wprm_ingredient' );
52
+            if ( ! isset( $term ) || $this->term_has_about_jsonld( $term ) ) {
53
+                continue;
54
+            }
55
+
56
+            $content_id = Wordpress_Content_Id::create_term( $term->term_id );
57
+            $this->content_service->set_about_jsonld( $content_id, $value );
58
+        }
59
+
60
+        $count        = count( $items );
61
+        $last_item    = end( $items );
62
+        $last_item_id = ( isset( $last_item->term_id ) ? $last_item->term_id : null );
63
+
64
+        return array( $count, $last_item_id );
65
+    }
66
+
67
+    /**
68
+     * Get the total number of posts to process.
69
+     *
70
+     * We only count published posts.
71
+     *
72
+     * @return int
73
+     */
74
+    public function get_total() {
75
+        return $this->store->get_total();
76
+    }
77
+
78
+    /**
79
+     * @param $term WP_Term
80
+     *
81
+     * @return bool true if the term has an about_jsonld otherwise false.
82
+     */
83
+    private function term_has_about_jsonld( $term ) {
84
+        $about_jsonld = $this->content_service->get_about_jsonld(
85
+            Wordpress_Content_Id::create_term( $term->term_id )
86
+        );
87
+
88
+        return $about_jsonld !== null;
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.