Skip to content

Commit

Permalink
Code Qaulity Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJ2324 committed Feb 4, 2025
1 parent 1a4322c commit 0aa813c
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 78 deletions.
6 changes: 3 additions & 3 deletions examples/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
$Account['name'] = 'Audit Log Test - Updated';
$Account['assigned_user_id'] = 'seed_max_id';
$Account->save();
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";
$Account->audit();
echo "Audit Log: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Audit Log: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand All @@ -36,4 +36,4 @@
} catch (Exception $ex) {
echo "Exception Occurred: " . $ex->getMessage();
echo $ex->getTraceAsString();
}
}
4 changes: 2 additions & 2 deletions examples/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$lead1 = $SugarAPI->module("Leads");
$lead2 = $SugarAPI->module("Leads");
Expand Down Expand Up @@ -44,4 +44,4 @@
} catch (Exception $ex) {
echo "Exception Occurred: " . $ex->getMessage();
echo $ex->getTraceAsString();
}
}
8 changes: 4 additions & 4 deletions examples/CRUD.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
// Create an Account called Test with a phone number
$Account = $SugarAPI->module('Accounts');
// You can set data via Array Access, Object Access, or set methods
Expand All @@ -24,15 +24,15 @@
$Account->set('employees', '100');
$Account['shipping_address_city'] = 'Indianapolis';
$Account->save();
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";

//Retrieve the Account in a new Object
$Account2 = $SugarAPI->module('Accounts', $Account['id']);
$Account2->retrieve();
echo "Retrieved Account: " . json_encode($Account2->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Retrieved Account: " . json_encode($Account2->toArray(), JSON_PRETTY_PRINT) . "\n";
//Delete the Account
$Account2->delete();
echo "Deleted Response: " . json_encode($Account2->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Deleted Response: " . json_encode($Account2->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/DuplicateCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
//Create a new Account
$Account = $SugarAPI->module('Accounts')->set("name", "DuplicateCheck Test");
$Account->save();
echo "Account Created: {$Account['id']}\n";
// Run duplicate check
$Account->duplicateCheck();
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/Favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
//Create a new Account
$Account = $SugarAPI->module('Accounts')->set("name", "Favorite Test");
$Account->save();
Expand All @@ -29,4 +29,4 @@
} catch (Exception $ex) {
echo "Exception Occurred: " . $ex->getMessage();
echo $ex->getTraceAsString();
}
}
6 changes: 3 additions & 3 deletions examples/FileManipulation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Note = $SugarAPI->module('Notes')->set("name", "Test");
//Create a note with subject
$Note->save();
echo "Saved Note ID: {$Note['id']}<br>";
echo "Attempting to attach $file...";
$Note->attachFile('filename', $file, true, 'testtest.txt');
echo "File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n";

$Note = $SugarAPI->module('Notes');
echo "Uploading temp file for new note...";
$Note->tempFile('filename', $file);
echo "Temp File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Temp File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
$Note->set('name', 'This is a test');
$Note->save();
echo "Note ID: {$Note['id']}\n";
Expand Down
4 changes: 2 additions & 2 deletions examples/FilterAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Accounts = $SugarAPI->list('Accounts');
$Accounts->filter()->and()
Expand Down Expand Up @@ -40,7 +40,7 @@
->endDate()
->endOr();
echo "Filtering Accounts that are created between dates, or in the last 7 days: "
. json_encode($Accounts->filter()->compile(),JSON_PRETTY_PRINT) . "\n";
. json_encode($Accounts->filter()->compile(), JSON_PRETTY_PRINT) . "\n";
$Accounts->fetch();
echo "Accounts: " . json_encode($Accounts->toArray(), JSON_PRETTY_PRINT) . "\n";
} else {
Expand Down
8 changes: 4 additions & 4 deletions examples/FilterRelated.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
$Accounts = $SugarAPI->list('Accounts');
$Accounts->fetch();
//Get first Account in Collection
$Account = $Accounts->at(1);
//Execute Related contacts count API call
$Account->getRelated('contacts', true);
echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
//Assuming there are >0 related contacts, filter them by first name contain an `s`
$Filter = $Account->filterRelated('contacts')->contains('first_name', 's');
echo "Filter Def for API: " . json_encode($Filter->compile(),JSON_PRETTY_PRINT) . "\n";
echo "Filter Def for API: " . json_encode($Filter->compile(), JSON_PRETTY_PRINT) . "\n";
$Filter->execute();
echo "Response:" . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Response:" . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/ModuleEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Enum = $SugarAPI->enum('Accounts', 'account_type')->execute();
echo "Account Type options: " . json_encode($Enum->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Account Type options: " . json_encode($Enum->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
4 changes: 2 additions & 2 deletions examples/NoteAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";

$Note = $SugarAPI->note()->set("name", "Test");
echo "Creating Note with multiple attachments: ";
Expand All @@ -34,7 +34,7 @@
//Add attachment_list field to retrieve request so we can see uploaded files
$Note->addField('attachment_list');
$Note->retrieve();
echo "Attachments: " . json_encode($Note->attachment_list,JSON_PRETTY_PRINT) . "\n";
echo "Attachments: " . json_encode($Note->attachment_list, JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
8 changes: 4 additions & 4 deletions examples/RelateRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
$Account = $SugarAPI->module('Accounts')->set("name", "Relate Records Test");
$Account->save();
echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";

$Opportunity = $SugarAPI->module('Opportunities');
$Opportunity['name'] = 'Test Opportunity';
$Opportunity['description'] = 'This opportunity was created via the SugarCRM PHP REST Client v1 to test creating relationships.';
$Opportunity->save();
echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(), JSON_PRETTY_PRINT) . "\n";

echo "Relating Opportunity to Account: ";
$Account->relate('opportunities', $Opportunity['id']);
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
} else {
echo "Could not login.";
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
Expand Down
6 changes: 3 additions & 3 deletions examples/Sudo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
try {
if ($SugarAPI->isAuthenticated()) {
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
if ($SugarAPI->sudo('will')) {
echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
$Me = $SugarAPI->me();
$Me->retrieve();
echo "User: " . json_encode($Me->toArray(),JSON_PRETTY_PRINT) . "\n";
echo "User: " . json_encode($Me->toArray(), JSON_PRETTY_PRINT) . "\n";
}
} else {
echo "Could not login.";
Expand Down
6 changes: 3 additions & 3 deletions examples/include.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
require_once __DIR__ . '/../vendor/autoload.php';

$server = 'localhost';
$credentials = array(
$credentials = [
'username' => 'admin',
'password' => 'asdf',
'platform' => 'base'
);
'platform' => 'base',
];
2 changes: 1 addition & 1 deletion src/Auth/SugarOAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function generateUniqueCacheString(array $creds): string
$key = '';
try {
$ep = $this->getActionEndpoint(self::ACTION_AUTH);
$key = preg_replace("/\/rest\/v[^\/]+\//","",$ep->getBaseUrl());
$key = preg_replace("/\/rest\/v[^\/]+\//", "", $ep->getBaseUrl());
} catch (\Exception) {
$this->getLogger()->info("Cannot use server in cache string.");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ abstract class AbstractSugarBeanEndpoint extends ModelEndpoint implements SugarE
protected static array $_DEFAULT_PROPERTIES = [
self::PROPERTY_URL => '$module/$id/$:action/$:actionArg1/$:actionArg2/$:actionArg3',
self::PROPERTY_HTTP_METHOD => 'GET',
self::PROPERTY_AUTH => true
self::PROPERTY_AUTH => true,
];

/**
Expand Down Expand Up @@ -380,7 +380,7 @@ public function relate(string $linkName, string $related_id): static
*/
public function auditLog(?int $limit = null): AuditLog
{
$auditCollection = new AuditLog([],['module' => $this->getModule(), 'id' => $this->get('id')]);
$auditCollection = new AuditLog([], ['module' => $this->getModule(), 'id' => $this->get('id')]);

if ($limit !== null) {
$auditCollection->setLimit($limit);
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoint/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class AuditLog extends SugarBeanCollection
self::PROPERTY_URL => '$module/$id/audit',
self::PROPERTY_AUTH => true,
];
}
}
4 changes: 1 addition & 3 deletions src/Endpoint/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarCollectionEndpoint;

class Collection extends AbstractSugarCollectionEndpoint
{
}
class Collection extends AbstractSugarCollectionEndpoint {}
4 changes: 2 additions & 2 deletions src/Endpoint/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function addAttachments(array $files, bool $async = true): self
if ($async) {
$responses = Utils::unwrap($promises);
$Note = new Note();
foreach($responses as $response){
foreach ($responses as $response) {
$Note->setResponse($response);
$this->parseAttachmentUploadResponse($Note->getResponseBody());
}
Expand All @@ -51,4 +51,4 @@ public function addAttachments(array $files, bool $async = true): self

return $this;
}
}
}
4 changes: 1 addition & 3 deletions src/Endpoint/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarEndpoint;

class Generic extends AbstractSugarEndpoint
{
}
class Generic extends AbstractSugarEndpoint {}
6 changes: 3 additions & 3 deletions src/Endpoint/MLPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MLPackage extends SugarBean
self::ACTION_ENABLE => 'GET',
self::ACTION_DISABLE => 'GET',
self::ACTION_INSTALL_STATUS => 'GET',
self::BEAN_ACTION_ATTACH_FILE => 'POST'
self::BEAN_ACTION_ATTACH_FILE => 'POST',
];

protected bool $_installing = false;
Expand Down Expand Up @@ -99,7 +99,7 @@ protected function parseResponse(Response $response): void
$this->_installing = false;
break;
case self::ACTION_INSTALL_STATUS:
if (!empty($data['message'])){
if (!empty($data['message'])) {
$this->_installOutput = $data['message'] ?? [];
}
break;
Expand All @@ -118,4 +118,4 @@ protected function configureFileUploadQueryParams(): array
{
return [];
}
}
}
4 changes: 2 additions & 2 deletions src/Endpoint/ModuleLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ModuleLoader extends CollectionEndpoint
self::PROPERTY_URL => 'Administration/packages/$:filter',
self::PROPERTY_RESPONSE_PROP => 'packages',
self::PROPERTY_HTTP_METHOD => 'GET',
self::PROPERTY_AUTH => true
self::PROPERTY_AUTH => true,
];

protected string $_modelInterface = MLPackage::class;
Expand Down Expand Up @@ -67,4 +67,4 @@ public function newPackage(): MLPackage
{
return $this->generateEndpoint(MLPackage::class);
}
}
}
4 changes: 2 additions & 2 deletions src/Endpoint/Provider/SugarEndpointProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class SugarEndpointProvider extends VersionedEndpointProvider
self::ENDPOINT_PROPERTIES => [
Generic::PROPERTY_URL => 'oauth2/logout',
Generic::PROPERTY_AUTH => true,
Generic::PROPERTY_HTTP_METHOD => "POST"
Generic::PROPERTY_HTTP_METHOD => "POST",
],
],
[
Expand Down Expand Up @@ -154,6 +154,6 @@ class SugarEndpointProvider extends VersionedEndpointProvider
self::ENDPOINT_NAME => 'mlp',
self::ENDPOINT_CLASS => MLPackage::class,
self::ENDPOINT_PROPERTIES => [],
]
],
];
}
4 changes: 1 addition & 3 deletions src/Endpoint/Smart.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Sugarcrm\REST\Endpoint\Abstracts\AbstractSmartSugarEndpoint;

class Smart extends AbstractSmartSugarEndpoint
{
}
class Smart extends AbstractSmartSugarEndpoint {}
5 changes: 1 addition & 4 deletions src/Endpoint/SugarBeanCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarBeanCollectionEndpoint;

class SugarBeanCollection extends AbstractSugarBeanCollectionEndpoint
{

}
class SugarBeanCollection extends AbstractSugarBeanCollectionEndpoint {}
2 changes: 1 addition & 1 deletion tests/Endpoint/Data/BulkRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testAsArray(): void

$Request = new Request("POST", 'http://localhost/rest/v11/Accounts', ['Content-Type' => 'application/json'], json_encode(['foo' => 'bar']));

$Filter = new ModuleFilter([],['Contacts']);
$Filter = new ModuleFilter([], ['Contacts']);
$Filter->setBaseUrl('http://localhost/rest/v11');
$Filter->filter()->equals('foo', 'bar');

Expand Down
Loading

0 comments on commit 0aa813c

Please sign in to comment.