CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • super keen zend
Pages: [1]

Author Topic: super keen zend  (Read 782 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
super keen zend
February 25, 2011, 12:41:58 am
I just installed Zend Studio which is like eclipse on steriods because I wanted to check out the extra functions.

Suddenly my Civi code base was littered with error notices!

The one at the bottom was a pretty good spot - it tells me that  $apiFile is not defined (which is an error for my European A-teamers). It also points out quite a few other things that are quite handy ... like who would have noticed that      $campaignId on line 253 of class CRM_Campaign_Form_Task_Reserve if not defined anywhere if I hadn't looked at my Zend errors


But the most common ones are 'assignment in condition' http://bytes.com/topic/php/answers/876224-assignments-conditions-should-avoided. Is this really something that should be phased out of Civi code?




Error for A-Team $apiFile is not defined
Code: [Select]
/**
 * @param $entity
 * @param $rest_interface : boolean
 *   In case of TRUE, we need to set the base path explicitly.
 */
function civicrm_api_include($entity, $rest_interface = FALSE) {
  $version = civicrm_get_api_version();
  $camel_name = civicrm_api_get_camel_name($entity);
  $file = 'api/v'. $version .'/'. $camel_name .'.php';
 
  if ( $rest_interface ) {
      $apiPath = substr( $_SERVER['SCRIPT_FILENAME'], 0, -15 );
      // check to ensure file exists, else die
      if ( ! file_exists( $apiPath . $apiFile ) ) {
          return self::error( 'Unknown function invocation.' );
      }
      $file = $apiPath . $file;
  }
 
  require_once $file;
}
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: super keen zend
February 25, 2011, 03:12:14 am
Zend also asks if

        $this->assertTrue($ret, ' [browser] clicked link '. t($label) . " ($url_target) from $url_before");

should be
        $this->assertTrue($ret, ' [browser] clicked link '. ts($label) . " ($url_target) from $url_before");

or if there is a reason to use the drupal function

class CiviTestCase

line 145
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

donquixote

  • I post occasionally
  • **
  • Posts: 42
  • Karma: 3
  • CiviCRM version: none
  • CMS version: Drupal
  • MySQL version: 5
  • PHP version: 5.2
Re: super keen zend
February 25, 2011, 08:54:41 am
Wow, this is embarrassing. What was I thinking?
Probably this was copied/adapted from somewhere else, but still..

There is also this "self::error" which looks wrong in a function context.

For the record, this could be copied from
CRM_Utils_REST::process( &$args, $restInterface = true )

with

        if ( $restInterface ) {
            $apiPath = substr( $_SERVER['SCRIPT_FILENAME'] , 0 ,-15 );
            // check to ensure file exists, else die
            if ( ! file_exists( $apiPath . $apiFile ) ) {
                return self::error( 'Unknown function invocation.' );
            }
        } else {
            $apiPath = null;
        }

(looking at r32131 of trunk)

I should definitely have spent more time on this, or someone else would have needed to have a look after the commit.

Note:
If we get rid of the nameclash problem pointed out in http://forum.civicrm.org/index.php/topic,18712.0.html, a lot of the code in api.php will become obsolete.

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: super keen zend
March 01, 2011, 12:08:59 am
Looks like I have to push my intention of playing with Zend forward!? But first.........too many things, it will be summer :-)
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: super keen zend
March 01, 2011, 01:40:04 am
I think that eclipse does this error checking too actuallly - but the function rename might be worth paying the ZEND $ for - not sure but I have 57 days to decide
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • super keen zend

This forum was archived on 2017-11-26.