Skip to content

Commit 2029cb0

Browse files
committed
Update PSR-2 code standard and add Custom query Doc in Readme
1 parent 53c3479 commit 2029cb0

File tree

11 files changed

+70
-65
lines changed

11 files changed

+70
-65
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ use Codexshaper\WooCommerce\Facades\Order;
4545
4646
public function orders()
4747
{
48-
return Order::all();
48+
$orders = Order::all();
49+
// Pass options as an array
50+
$orders = Order::all(['status' => 'processing']);
51+
// Call Custom query with WHERE clause
52+
$orders = Order::where(['status' => 'processing'])->get();
4953
}
5054
5155
public function order( Request $request )

src/Facades/Customer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
namespace Codexshaper\WooCommerce\Facades;
33

44
use Illuminate\Support\Facades\Facade;
@@ -14,4 +14,4 @@ protected static function getFacadeAccessor()
1414
{
1515
return 'Codexshaper\WooCommerce\Models\Customer';
1616
}
17-
}
17+
}

src/Facades/Order.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
namespace Codexshaper\WooCommerce\Facades;
33

44
use Illuminate\Support\Facades\Facade;
@@ -14,4 +14,4 @@ protected static function getFacadeAccessor()
1414
{
1515
return 'Codexshaper\WooCommerce\Models\Order';
1616
}
17-
}
17+
}

src/Facades/Product.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
namespace Codexshaper\WooCommerce\Facades;
33

44
use Illuminate\Support\Facades\Facade;
@@ -14,4 +14,4 @@ protected static function getFacadeAccessor()
1414
{
1515
return 'Codexshaper\WooCommerce\Models\Product';
1616
}
17-
}
17+
}

src/Facades/WooCommerce.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?php
1+
<?php
22
namespace Codexshaper\WooCommerce\Facades;
33

4-
use Illuminate\Support\Facades\Facade;
54
use Codexshaper\WooCommerce\WooCommerceApi;
5+
use Illuminate\Support\Facades\Facade;
6+
67
class WooCommerce extends Facade
78
{
89
/**
@@ -14,4 +15,4 @@ protected static function getFacadeAccessor()
1415
{
1516
return WooCommerceApi::class;
1617
}
17-
}
18+
}

src/Facades/WoocommerceFacade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
namespace Codexshaper\Woocommerce\Facades;
33

44
use Illuminate\Support\Facades\Facade;
@@ -14,4 +14,4 @@ protected static function getFacadeAccessor()
1414
{
1515
return 'Codexshaper\Woocommerce\WoocommerceApi';
1616
}
17-
}
17+
}

src/Traits/WoocommerceTrait.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
trait WooCommerceTrait
66
{
7-
/**
8-
* GET method.
9-
* Retrieve data
10-
*
11-
* @param string $endpoint API endpoint.
12-
* @param array $options
13-
*
14-
* @return array
15-
*/
16-
public function all($endpoint='', $options = [])
17-
{
18-
return $this->client->get($endpoint, $options);
19-
}
7+
/**
8+
* GET method.
9+
* Retrieve data
10+
*
11+
* @param string $endpoint API endpoint.
12+
* @param array $options
13+
*
14+
* @return array
15+
*/
16+
public function all($endpoint = '', $options = [])
17+
{
18+
return $this->client->get($endpoint, $options);
19+
}
2020
/**
2121
* GET method.
2222
* Retrieve Single data
@@ -26,7 +26,7 @@ public function all($endpoint='', $options = [])
2626
*
2727
* @return array
2828
*/
29-
public function find($endpoint='', $options = [])
29+
public function find($endpoint = '', $options = [])
3030
{
3131
return $this->client->get($endpoint, $options);
3232
}
@@ -103,7 +103,7 @@ public function current()
103103
*/
104104
public function countResults()
105105
{
106-
return (int)$this->getResponse()->getHeaders()['X-WP-Total'];
106+
return (int) $this->getResponse()->getHeaders()['X-WP-Total'];
107107
}
108108
/**
109109
* Count the total pages and return
@@ -112,7 +112,7 @@ public function countResults()
112112
*/
113113
public function countPages()
114114
{
115-
return (int)$this->getResponse()->getHeaders()['X-WP-TotalPages'];
115+
return (int) $this->getResponse()->getHeaders()['X-WP-TotalPages'];
116116
}
117117
/**
118118
* Return the previous page number
@@ -121,8 +121,8 @@ public function countPages()
121121
*/
122122
public function previous()
123123
{
124-
$currentPage = $this->current();
125-
return ( --$currentPage > 1) ? $currentPage : null;
124+
$currentPage = $this->current();
125+
return (--$currentPage > 1) ? $currentPage : null;
126126
}
127127
/**
128128
* Return the next page number
@@ -131,7 +131,7 @@ public function previous()
131131
*/
132132
public function next()
133133
{
134-
$currentPage = $this->current();
135-
return ( ++$currentPage < $this->countPages()) ? $currentPage : null;
134+
$currentPage = $this->current();
135+
return (++$currentPage < $this->countPages()) ? $currentPage : null;
136136
}
137-
}
137+
}

src/WooCommerceServiceProvider.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ class WooCommerceServiceProvider extends ServiceProvider
1414
* @return void
1515
*/
1616
public function boot()
17-
{
17+
{
1818
$this->publishes([
19-
__DIR__.'/config/woocommerce.php' => config_path('woocommerce.php'),
20-
],'woocommerce');
19+
__DIR__ . '/config/woocommerce.php' => config_path('woocommerce.php'),
20+
], 'woocommerce');
2121
}
2222

2323
/**
@@ -27,13 +27,13 @@ public function boot()
2727
*/
2828
public function register()
2929
{
30-
30+
3131
$this->mergeConfigFrom(
32-
__DIR__.'/config/woocommerce.php', 'woocommerce'
32+
__DIR__ . '/config/woocommerce.php', 'woocommerce'
3333
);
3434

35-
$this->app->singleton('WooCommerceApi', function(){
36-
return new WooCommerceApi();
35+
$this->app->singleton('WooCommerceApi', function () {
36+
return new WooCommerceApi();
3737
});
3838
$this->app->alias('Codexshaper\Woocommerce\WooCommerceApi', 'WoocommerceApi');
3939
}

src/WoocommerceApi.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77

88
class WooCommerceApi
99
{
10-
use WooCommerceTrait;
10+
use WooCommerceTrait;
1111

12-
protected $client;
12+
protected $client;
1313

14-
public function __construct()
15-
{
16-
$this->client = new Client(
17-
config('woocommerce.store_url'),
18-
config('woocommerce.consumer_key'),
19-
config('woocommerce.consumer_secret'),
14+
public function __construct()
15+
{
16+
$this->client = new Client(
17+
config('woocommerce.store_url'),
18+
config('woocommerce.consumer_key'),
19+
config('woocommerce.consumer_secret'),
2020
[
21-
'version' => 'wc/'.config('woocommerce.api_version'),
22-
'wp_api' => config('woocommerce.wp_api_integration'),
23-
'verify_ssl' => config('woocommerce.verify_ssl'),
21+
'version' => 'wc/' . config('woocommerce.api_version'),
22+
'wp_api' => config('woocommerce.wp_api_integration'),
23+
'verify_ssl' => config('woocommerce.verify_ssl'),
2424
'query_string_auth' => config('woocommerce.query_string_auth'),
25-
'timeout' => config('woocommerce.timeout'),
25+
'timeout' => config('woocommerce.timeout'),
2626
]);
27-
}
27+
}
2828

29-
}
29+
}

src/config/woocommerce.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@
66
* Store URL eg: http://example.com
77
*================================================================================
88
*/
9-
'store_url' => env('WOOCOMMERCE_STORE_URL', 'YOUR_STORE_URL'),
9+
'store_url' => env('WOOCOMMERCE_STORE_URL', 'YOUR_STORE_URL'),
1010

1111
/**
1212
*================================================================================
1313
* Consumer Key
1414
*================================================================================
1515
*/
16-
'consumer_key' => env('WOOCOMMERCE_CONSUMER_KEY', 'YOUR_CONSUMER_KEY'),
16+
'consumer_key' => env('WOOCOMMERCE_CONSUMER_KEY', 'YOUR_CONSUMER_KEY'),
1717

1818
/**
1919
* Consumer Secret
2020
*/
21-
'consumer_secret' => env('WOOCOMMERCE_CONSUMER_SECRET', 'YOUR_CONSUMER_SECRET'),
21+
'consumer_secret' => env('WOOCOMMERCE_CONSUMER_SECRET', 'YOUR_CONSUMER_SECRET'),
2222

2323
/**
2424
*================================================================================
2525
* SSL support
2626
*================================================================================
2727
*/
28-
'verify_ssl' => env('WOOCOMMERCE_VERIFY_SSL', false),
28+
'verify_ssl' => env('WOOCOMMERCE_VERIFY_SSL', false),
2929

3030
/**
3131
*================================================================================
3232
* Woocommerce API version
3333
*================================================================================
3434
*/
35-
'api_version' => env('WOOCOMMERCE_API_VERSION', 'v3'),
35+
'api_version' => env('WOOCOMMERCE_API_VERSION', 'v3'),
3636

3737
/**
3838
*================================================================================
3939
* Enable WP API Integration
4040
*================================================================================
4141
*/
42-
'wp_api' => env('WP_API_INTEGRATION', true),
42+
'wp_api' => env('WP_API_INTEGRATION', true),
4343

4444
/**
4545
*================================================================================
@@ -55,5 +55,5 @@
5555
*================================================================================
5656
*/
5757

58-
'timeout' => env('WOOCOMMERCE_WP_TIMEOUT', 15),
59-
];
58+
'timeout' => env('WOOCOMMERCE_WP_TIMEOUT', 15),
59+
];

0 commit comments

Comments
 (0)