Skip to content

Commit ce7f311

Browse files
chore(ci): homeboy autofix — refactor (77 files, 170 fixes)
duplicatefunction: 134 BlueskyAuth.php, BlueskyDeleteAbility.php, BlueskyReadAbility.php, BlueskyUpdateAbility.php, FacebookAuth.php, FacebookDeleteAbility.php, FacebookReadAbility.php, FacebookUpdateAbility.php, FetchRedditAbility.php, HasCheckPermission.php, HasGetAccountDetails.php, HasRemoveAccount.php, InstagramAuth.php, InstagramCommentReplyAbility.php, InstagramDeleteAbility.php, InstagramReadAbility.php, InstagramUpdateAbility.php, LinkedInAuth.php, LinkedInDeleteAbility.php, LinkedInReadAbility.php, LinkedInUpdateAbility.php, PinterestAnalyticsAbility.php, PinterestAuth.php, PinterestDeleteAbility.php, PinterestReadAbility.php, PinterestUpdateAbility.php, RedditAuth.php, ReplyRedditAbility.php, SubmitRedditAbility.php, ThreadsAuth.php, ThreadsDeleteAbility.php, ThreadsReadAbility.php, ThreadsUpdateAbility.php, TwitterAuth.php, TwitterDeleteAbility.php, TwitterReadAbility.php, TwitterUpdateAbility.php, VoteRedditAbility.php missingmethod: 31 BlueskyPublishAbility.php, BlueskySettings.php, FacebookPublishAbility.php, FacebookSettings.php, InstagramPublishAbility.php, InstagramSettings.php, LinkedInPublishAbility.php, LinkedInSettings.php, PinterestBoardsAbility.php, PinterestPublishAbility.php, PinterestSettings.php, RedditSettings.php, ThreadsPublishAbility.php, TwitterPublishAbility.php, TwitterSettings.php intramethodduplicate: 1 UpdateInstagram.php phpcbf: 1 (multiple) short-ternary: 1 (multiple) wp-filesystem: 1 (single) yoda-condition: 1 (single)
1 parent 272e0ea commit ce7f311

77 files changed

Lines changed: 1984 additions & 668 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace DataMachineSocials\Abilities\Traits;
4+
5+
use DataMachine\Abilities\PermissionHelper;
6+
7+
/**
8+
* Shared trait for the `checkPermission` method.
9+
*
10+
* Extracted by homeboy audit --fix from duplicate implementations.
11+
*/
12+
trait HasCheckPermission {
13+
public function checkPermission(): bool {
14+
return PermissionHelper::can_manage();
15+
}
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace DataMachineSocials\Handlers\Traits;
4+
5+
/**
6+
* Shared trait for the `get_account_details` method.
7+
*
8+
* Extracted by homeboy audit --fix from duplicate implementations.
9+
*/
10+
trait HasGetAccountDetails {
11+
/**
12+
* Get stored Threads account details
13+
*
14+
* @return array|null Account details or null
15+
*/
16+
public function get_account_details(): ?array {
17+
$account = $this->get_account();
18+
if ( empty( $account ) || ! is_array( $account ) ) {
19+
return null;
20+
}
21+
return $account;
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace DataMachineSocials\Handlers\Traits;
4+
5+
/**
6+
* Shared trait for the `remove_account` method.
7+
*
8+
* Extracted by homeboy audit --fix from duplicate implementations.
9+
*/
10+
trait HasRemoveAccount {
11+
/**
12+
* Remove stored Reddit account details
13+
*
14+
* @return bool Success status
15+
*/
16+
public function remove_account(): bool {
17+
return $this->clear_account();
18+
}
19+
}

homeboy.json

Lines changed: 702 additions & 0 deletions
Large diffs are not rendered by default.

inc/Abilities/Bluesky/BlueskyDeleteAbility.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
use DataMachine\Abilities\PermissionHelper;
1515
use DataMachineSocials\Handlers\Bluesky\BlueskyAuth;
16+
use DataMachineSocials\Abilities\Traits\HasCheckPermission;
1617

1718
defined( 'ABSPATH' ) || exit;
1819

1920
class BlueskyDeleteAbility {
21+
use HasCheckPermission;
22+
2023

2124
private static bool $registered = false;
2225

@@ -73,10 +76,6 @@ private function registerAbilities(): void {
7376
}
7477
}
7578

76-
public function checkPermission(): bool {
77-
return PermissionHelper::can_manage();
78-
}
79-
8079
public function execute( array $input ): array|\WP_Error {
8180
$auth = $this->getAuthProvider();
8281
if ( ! $auth ) {

inc/Abilities/Bluesky/BlueskyPublishAbility.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,4 +434,85 @@ private static function fetch_og_tags( string $url ): array|\WP_Error {
434434

435435
return $og;
436436
}
437+
438+
private function getAuthProvider(): ?BlueskyAuth {
439+
if ( ! class_exists( '\DataMachine\Abilities\AuthAbilities' ) ) {
440+
return null;
441+
}
442+
443+
$auth = new \DataMachine\Abilities\AuthAbilities();
444+
$provider = $auth->getProvider( 'bluesky' );
445+
446+
if ( ! $provider instanceof BlueskyAuth ) {
447+
return null;
448+
}
449+
450+
return $provider;
451+
}
452+
453+
public function checkPermission(): bool {
454+
return PermissionHelper::can_manage();
455+
}
456+
457+
public function execute( array $input ): array|\WP_Error {
458+
$auth = $this->getAuthProvider();
459+
if ( ! $auth ) {
460+
return new \WP_Error( 'missing_auth', 'Bluesky auth provider not available', array( 'status' => 401 ) );
461+
}
462+
463+
$session = $auth->get_session();
464+
if ( empty( $session['accessJwt'] ) ) {
465+
return new \WP_Error( 'missing_auth', 'Bluesky session not available', array( 'status' => 401 ) );
466+
}
467+
468+
if ( empty( $input['post_uri'] ) ) {
469+
return new \WP_Error( 'missing_param', 'post_uri is required', array( 'status' => 400 ) );
470+
}
471+
472+
$did = $session['did'];
473+
474+
// Parse rkey from AT URI: at://did:plc:xxx/app.bsky.feed.post/rkey
475+
$post_uri = $input['post_uri'];
476+
$uri_parts = explode( '/', $post_uri );
477+
$rkey = end( $uri_parts );
478+
479+
if ( empty( $rkey ) ) {
480+
return new \WP_Error( 'api_error', 'Could not extract rkey from post URI: ' . $post_uri, array( 'status' => 500 ) );
481+
}
482+
483+
$response = wp_remote_post(
484+
'https://bsky.social/xrpc/com.atproto.repo.deleteRecord',
485+
array(
486+
'timeout' => 30,
487+
'headers' => array(
488+
'Authorization' => 'Bearer ' . $session['accessJwt'],
489+
'Content-Type' => 'application/json',
490+
),
491+
'body' => wp_json_encode( array(
492+
'repo' => $did,
493+
'collection' => 'app.bsky.feed.post',
494+
'rkey' => $rkey,
495+
) ),
496+
)
497+
);
498+
499+
if ( is_wp_error( $response ) ) {
500+
return new \WP_Error( 'api_error', $response->get_error_message(), array( 'status' => 500 ) );
501+
}
502+
503+
$status_code = wp_remote_retrieve_response_code( $response );
504+
505+
if ( 200 === $status_code || 204 === $status_code ) {
506+
return array(
507+
'success' => true,
508+
'data' => array(
509+
'post_uri' => $input['post_uri'],
510+
'deleted' => true,
511+
),
512+
);
513+
}
514+
515+
$body = json_decode( wp_remote_retrieve_body( $response ), true );
516+
return new \WP_Error( 'api_error', $body['error'] ?? 'Failed to delete post', array( 'status' => 500 ) );
517+
}
437518
}

inc/Abilities/Bluesky/BlueskyReadAbility.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
use DataMachine\Abilities\PermissionHelper;
1616
use DataMachine\Core\HttpClient;
1717
use DataMachineSocials\Handlers\Bluesky\BlueskyAuth;
18+
use DataMachineSocials\Abilities\Traits\HasCheckPermission;
1819

1920
defined( 'ABSPATH' ) || exit;
2021

2122
class BlueskyReadAbility {
23+
use HasCheckPermission;
24+
2225

2326
private static bool $registered = false;
2427

@@ -89,10 +92,6 @@ private function registerAbilities(): void {
8992
}
9093
}
9194

92-
public function checkPermission(): bool {
93-
return PermissionHelper::can_manage();
94-
}
95-
9695
public function execute( array $input ): array|\WP_Error {
9796
$action = $input['action'] ?? 'list';
9897

inc/Abilities/Bluesky/BlueskyUpdateAbility.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
use DataMachine\Abilities\PermissionHelper;
1616
use DataMachineSocials\Handlers\Bluesky\BlueskyAuth;
17+
use DataMachineSocials\Abilities\Traits\HasCheckPermission;
18+
use DataMachineSocials\Abilities\Bluesky\BlueskyDeleteAbility;
1719

1820
defined( 'ABSPATH' ) || exit;
1921

2022
class BlueskyUpdateAbility {
23+
use HasCheckPermission;
24+
2125

2226
private static bool $registered = false;
2327

@@ -79,10 +83,6 @@ private function registerAbilities(): void {
7983
}
8084
}
8185

82-
public function checkPermission(): bool {
83-
return PermissionHelper::can_manage();
84-
}
85-
8686
public function execute( array $input ): array|\WP_Error {
8787
$action = $input['action'] ?? '';
8888

@@ -117,21 +117,6 @@ public function execute( array $input ): array|\WP_Error {
117117
}
118118
}
119119

120-
private function getAuthProvider(): ?BlueskyAuth {
121-
if ( ! class_exists( '\DataMachine\Abilities\AuthAbilities' ) ) {
122-
return null;
123-
}
124-
125-
$auth = new \DataMachine\Abilities\AuthAbilities();
126-
$provider = $auth->getProvider( 'bluesky' );
127-
128-
if ( ! $provider instanceof BlueskyAuth ) {
129-
return null;
130-
}
131-
132-
return $provider;
133-
}
134-
135120
private function deletePost( array $session, string $post_uri ): array|\WP_Error {
136121
$pds_url = $session['pds_url'];
137122
$did = $session['did'];

inc/Abilities/Facebook/FacebookDeleteAbility.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
use DataMachine\Abilities\PermissionHelper;
1515
use DataMachineSocials\Handlers\Facebook\FacebookAuth;
16+
use DataMachineSocials\Abilities\Traits\HasCheckPermission;
1617

1718
defined( 'ABSPATH' ) || exit;
1819

1920
class FacebookDeleteAbility {
21+
use HasCheckPermission;
22+
2023

2124
private static bool $registered = false;
2225

@@ -75,10 +78,6 @@ private function registerAbilities(): void {
7578
}
7679
}
7780

78-
public function checkPermission(): bool {
79-
return PermissionHelper::can_manage();
80-
}
81-
8281
public function execute( array $input ): array|\WP_Error {
8382
$auth = $this->getAuthProvider();
8483
if ( ! $auth ) {

inc/Abilities/Facebook/FacebookPublishAbility.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,54 @@ private static function post_comment( string $post_id, string $message, string $
358358
private static function build_graph_url( string $path ): string {
359359
return 'https://graph.facebook.com/v23.0/' . ltrim( $path, '/' );
360360
}
361+
362+
private function getAuthProvider(): ?FacebookAuth {
363+
$auth_abilities = new \DataMachine\Abilities\AuthAbilities();
364+
$provider = $auth_abilities->getProvider( 'facebook' );
365+
366+
if ( $provider instanceof FacebookAuth ) {
367+
return $provider;
368+
}
369+
370+
return null;
371+
}
372+
373+
public function checkPermission(): bool {
374+
return PermissionHelper::can_manage();
375+
}
376+
377+
public function execute( array $input ): array|\WP_Error {
378+
$action = $input['action'] ?? 'list';
379+
380+
$auth = $this->getAuthProvider();
381+
if ( ! $auth ) {
382+
return new \WP_Error( 'missing_auth', 'Facebook auth provider not available', array( 'status' => 401 ) );
383+
}
384+
385+
// Facebook uses page_access_token for page operations.
386+
$page_token = $auth->get_page_access_token();
387+
if ( empty( $page_token ) ) {
388+
return new \WP_Error( 'missing_auth', 'Facebook page access token unavailable (expired or refresh failed)', array( 'status' => 401 ) );
389+
}
390+
391+
switch ( $action ) {
392+
case 'list':
393+
return $this->listPosts( $auth, $page_token, $input );
394+
395+
case 'get':
396+
if ( empty( $input['post_id'] ) ) {
397+
return new \WP_Error( 'missing_param', 'post_id is required for the get action', array( 'status' => 400 ) );
398+
}
399+
return $this->getPost( $page_token, $input['post_id'] );
400+
401+
case 'comments':
402+
if ( empty( $input['post_id'] ) ) {
403+
return new \WP_Error( 'missing_param', 'post_id is required for the comments action', array( 'status' => 400 ) );
404+
}
405+
return $this->getComments( $page_token, $input['post_id'], $input );
406+
407+
default:
408+
return new \WP_Error( 'api_error', "Unknown action: {$action}. Use list, get, or comments.", array( 'status' => 500 ) );
409+
}
410+
}
361411
}

0 commit comments

Comments
 (0)