Hello,

This module connects to an API at a Commerce as a Service Platform called SalesCloud. It is primarily intended to be used by other modules which are at the moment primarily under my development also but I am hopeful that others may use this module. The module contains simple functions to interact with the Rest API, like salescloud_index('entity'), and returns a standardized array.

Project page is here: https://www.drupal.org/sandbox/proton/2317483

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/proton/2317483.git salescloud
cd salescloud

Reviews:
https://www.drupal.org/node/2642870#comment-10719288
https://www.drupal.org/node/2649064#comment-10744616
https://www.drupal.org/node/2649336#comment-10744840

Best Regards,
Helgi.

Comments

proton created an issue. See original summary.

PA robot’s picture

Status: Active » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxproton2317483git

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

Helgi Andri Jónsson’s picture

Issue summary: View changes
Helgi Andri Jónsson’s picture

I spent the entire day reviewing the errors by the automated review tools and resolved them all. Learned alot about drupal coding standards, it was way more strict than I thought.

Helgi Andri Jónsson’s picture

Status: Needs work » Active
Helgi Andri Jónsson’s picture

Status: Active » Needs review
atul4drupal’s picture

Hello Helgi Andri Jónsson,

I understand it takes great effort to make your code comply to drupal standards :)

One thing I noticed while manually reviewing your code :

FILE : salescloud.admin.inc
1) Add a blank line at end of salescloud_admin_form() function.

I think it will be good to run your module against the auto code sniffer at pareview.sh and iron out the very few standardization issues you may find there.

Helgi Andri Jónsson’s picture

Hi atul4drupal,

Thanks for the comment. I already have run the repository through the auto code sniffer at pareview.sh and resolved the issues but it did not report the one you found.

Best Regards,
Helgi.

id.tarzanych’s picture

Hello Helgi,

Coding standards in your code are followed in correct way.
But there are some things that I am concerned about.

  1. I see that you've implemented 7 functions that just load variables. In general variable_get function is a common way to set form element's default value or set if condition. That will reduce your code with 43 lines.
    I suppose that you used them to beautify your code. In my opinion more efficient way is to have a single function that returns static array variable with all values.
  2. I am a bit concerned about salescloud() function. Each time it is executed a new SalesCloud object is created. Is this neccessary? I think that better way is to use Singleton pattern, or at least put this object to a static variable.
  3. Please put required modules dependencies into salescloud.info file.
  4. Try to put salescloud.api.inc file into files[] section of module info file instead of using require_once.

Thanks for your work!

Helgi Andri Jónsson’s picture

Hi Serge,

Thank you for reviewing the module. :)

1. I admit its to beautify the code but also to retain the option of changing the way they are called and I would appreciate if I could keep those functions. I understand it would reduce lines to merge them into one.
2. I introduced a singleton pattern: SalesCloud::Instance(arguments); and made the __constructor private.
3. I added composer manager as dependency to the module.info file.
4. I added salescloud.api.inc as a files[] to the module info file and removed the require_once.

Best Regards from Iceland,
Helgi.

?>

Helgi Andri Jónsson’s picture

Issue summary: View changes
Helgi Andri Jónsson’s picture

Issue summary: View changes
Helgi Andri Jónsson’s picture

Issue tags: +PAreview: review bonus
mmowers’s picture

Hi Helgi. Here's a manual code review, based on the Project Application Review Template.

Recommendations/Questions are in bold italics

Manual Review

Individual user account
[Yes: Follows] the guidelines for individual user accounts.
No duplication
[Yes: Does not cause] module duplication and/or fragmentation, as I could not find any other Drupal SalesCloud integrations.
Master Branch
[Yes: Follows] the guidelines for master branch, and the correct git clone command
Licensing
[Yes: Follows] the licensing requirements, as sandbox project uses GNU GPL v2, and there are no other licenses cited.
3rd party assets/code
[Yes: Follows] the guidelines for 3rd party assets/code, as none are included. One question: It looks like the Oauth2 Guzzle plugin is included in composer.json, but I didn't see Guzzle 5, though that is listed as a dependency too on the project page. Was that forgotten, or is it included somehow?
README.txt/README.md
[Yes: Follows] the guidelines for in-project documentation and/or the README Template, with all the necessary information in README.txt.
Code long/complex enough for review
[Yes: Follows] the guidelines for project length and complexity.
Secure code
[Yes: Meets] the security requirements as far as I can tell, though I am not familiar with the SalesCloud or Guzzle APIs and best practices. There are no writes to the db and proper handling of user input via standard drupal admin form.
Coding style & Drupal API usage
[List of identified issues in no particular order]

Nothing big, I can't see any blockers. Good work!

Helgi Andri Jónsson’s picture

Hi mmowevers,

The Oauth2 Guzzle plugin has a dependency by itself to Guzzle 5 and so composer will fetch it.

I want to specify php version in hook_requirements so that I can check the version continually in all phases of drupal.

Best Regards,
Helgi.

almaudoh’s picture

Some more reviews in addition to #9

   *
   * @return SalesCloud
   */
  public static function Instance($client_id, $secret, array $scope, $username, $password) {
    static $inst = null;
    if ($inst === null) {
      $inst = new SalesCloud($client_id, $secret, $scope, $username, $password);
    }

A better approach would be to declare a class level instance, instead of the function/method level static you are using:

  static $instance;

  public static function Instance($client_id, $secret, array $scope, $username, $password) {
    if (static::$instance === null) {
      static::$instance = new SalesCloud($client_id, $secret, $scope, $username, $password);
    }
    return static::$instance;

Also, nitpick, Drupal standards require method names to start with lowercase and use camelCase

  private function __construct($client_id, $secret, array $scope, $username, $password) {
    $this->base = 'https://salescloud.is';
    .
    .
    .
  public function connect() {
    $return = array();

    $client = $this::client();

    try {
      $res = $client->post($this->base . '/api/2.0/system/connect', array('json' => array()));

Rather than hardcoding api paths, it would make sense to have them as settings (or at least constants) for more flexibility.

I also echo #9.1 about the use of variables namespace. It would be nicer if you bunched all of those into one 'salescloud_auth' setting or so. It's good practice to avoid overbloating the variables table. Consider if every module did the same thing?

Helgi Andri Jónsson’s picture

Hi almaudoh,

Thanks for reviewing the code. I have to ask if these are truly any project application blockers because this is a fairly small and simple module and I have been getting the impression from other project applications that we might be overreaching our selves.

I am very happy to get your input and I will implement the changes you recommend.

Best Regards,
Helgi.

almaudoh’s picture

@Helgi, these are not blockers, just recommendations.

klausi’s picture

@almaudoh: anything else that you found or should this now be RTBC?

almaudoh’s picture

@klausi, I think this should be RTBC, even though I didn't test the API all the way through since I have no salescloud account.

@Helgi, in the salescloud.api.inc, where http requests are made in the try block, the code in the catch block assumes that there is always a response. I had an instance where there wasn't a response, so I had to change the code to something like below to make it work.

    }
    catch (RequestException $e) {
      if ($e->getResponse()) {
        $return['headers'] = $e->getResponse()->getHeaders();
        $return['url'] = $e->getResponse()->getEffectiveUrl();
        $return['reason'] = $e->getResponse()->getReasonPhrase();
        $return['status_code'] = $e->getResponse()->getStatusCode();
        $return['protocol'] = $e->getResponse()->getProtocolVersion();
        $return['data'] = array();
      }
    }
almaudoh’s picture

Status: Needs review » Reviewed & tested by the community
Helgi Andri Jónsson’s picture

Hi almaudoh & klausi,

Thanks so much for the recommendations and I will implement them later today and comment back to confirm.

Best Regards,
Helgi.

Helgi Andri Jónsson’s picture

Hi almaudoh & klausi,

I have implemented all the recommendations:

The camelCase of instance method.
Class level instance.
Merged variable_get & variable_set calls into one function.
Added if($e->getReponse()) in case there is no response from API.

Looking forward to your replies.

Best Regards,
Helgi.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

Review of the 7.x-1.x branch (commit 363f4d1):

  • Coder Sniffer has found some issues with your code (please check the Drupal coding standards).
    
    FILE: /home/klausi/pareview_temp/salescloud.api.inc
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     24 | ERROR | Visibility must be declared on property "$instance"
    ----------------------------------------------------------------------
    
    Time: 627ms; Memory: 12Mb
    
  • No automated test cases were found, did you consider writing Simpletests or PHPUnit tests? This is not a requirement but encouraged for professional software development.

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.

manual review:

  1. "variable_set('salescloud_settings', $settings);": all variables defined by your module need to be removed in hook_uninstall(). Looks like you are now using only one variable?
  2. salescloud.api.inc: why do you build the $return arrays everywhere? I think it would be much more useful if you just return the actual response objects that people can use in a more readable manner.

Otherwise looks good to me.

Thanks for your contribution, Helgi!

I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

Helgi Andri Jónsson’s picture

Hi @klausi,

Thanks alot.

1. I completely forgot about those in hook_uninstall and will adjust it to the new variable_set.
2. Yeah I thought about that too. I will make a private function that handles the return array.

I will keep on making manual reviews from time to time. I have great respect for your contribution to the project application process.

Best Regards,
Helgi.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.