addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwchatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgoogleimageimagesinstagramlinklocation-pinmagnifying-glassmailminusmoremuplabelShape 3 + Rectangle 1outlookpersonplusprice-ribbonImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruseryahoo

Re: [php-49] Does this look ok for my constructor, or is it too hard to read?

From: Jd D.
Sent on: Thursday, February 14, 2013 8:02 AM

Thanks Mike :)

On Feb 14,[masked]:59 AM, "Mike Blaszczak" <[address removed]> wrote:
strpos() returns an int, not a bool. Seems a bit inconsistent to test NULL explicitly but not test the return from strpos() for != 0 explicitly.

Comments like "// !!!" could be more helpful.


On Wed, Feb 13, 2013 at 10:46 AM, Jd Daniel <[address removed]> wrote:
I know I overcomplicate stuff sometimes, just wanna make sure i'm not off the deep end for other devs. Cheers.

    /**
     * Creates a new Private_Service_Foo_Response object.
     *
     * @param string $data Response data returned by Foo
     * @param array  $info HTTP {@link http://us3.php.net/curl_getinfo metadata}
     *
     * @throws Private_Service_Foo_Exception
     */
    public function __construct($data, array $info)
    {
        $this->_dataString = $data;
        $this->_httpInfo   = $info;

        // If no error occurred, attempt to convert returned data to an object
        if(!$this->isError() && isset($info['url']))
        {
            // Convert JSON to StdClass object, XML to SimpleXMLElement
            if(strpos($info['url'], '.json'))
            {
                // throw error on bad json
                if (NULL !== ($this->dataObject = json_decode($data)) && JSON_ERROR_NONE === json_last_error())
                {
                    self::_throwException('Error parsing JSON file ' . $file . ': ' . json_last_error());
                }
            }
            else if(strpos($info['url'], '.xml'))
            {
                // throw error on bad xml
                libxml_use_internal_errors(true); // !!!
                if (FALSE === ($this->dataObject = simplexml_load_string($data)))
                {
                    self::_throwException('Error parsing XML file ' . $file . ': ' . implode(', ', libxml_get_errors()));
                }
            }
        }
    }


--
Jd Daniel || ERADO
Senior Applications Architect
7901 Delridge Way SW #36D, Seattle
C.    [masked]





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Jd Daniel ([address removed]) from The Seattle PHP Meetup Group.
To learn more about Jd Daniel, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Mike Blaszczak ([address removed]) from The Seattle PHP Meetup Group.
To learn more about Mike Blaszczak, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]

Our Sponsors

  • TUNE

    Meeting space and food

  • PluralSight

    PluralSight subscriptions for developer training

  • O'Reilly

    Disc Code: PCBW is good for 40% off print and 50% off ebooks and videos

  • JetBrains PhpStorm

    Occasional free licenses to raffle off at meetups

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy