<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Connecting the dots... &#187; Clean</title>
	<atom:link href="http://blog.rajatpandit.com/tag/clean/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rajatpandit.com</link>
	<description>Thoughts on Web Development, Infrastructure and Application Scalability</description>
	<lastBuildDate>Thu, 29 Dec 2011 13:21:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PHP CodeSniffer and common errors</title>
		<link>http://blog.rajatpandit.com/2009/10/01/php-code-sniffer-and-common-errors/</link>
		<comments>http://blog.rajatpandit.com/2009/10/01/php-code-sniffer-and-common-errors/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 14:06:29 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Clean]]></category>
		<category><![CDATA[code sniffer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[phpcs]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=382</guid>
		<description><![CDATA[I am currently writing a wrapper for PHPUnit for my employer which makes writing Selenium test cases for developers far easier. It would abstract them from the details of knowing...]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-384" title="sniffer11a" src="http://blog.rajatpandit.com/wp-content/uploads/2009/10/sniffer11a.jpg" alt="sniffer11a" width="322" height="193" />I am currently writing a wrapper for <a href="http://phpunit.de">PHPUnit</a> for my <a href="http://ipcmedia.com">employer</a> which makes writing <a href="http://seleniumhq.org/">Selenium</a> test cases for developers far easier. It would abstract them from the details of knowing server, urls, browser versions, reporting etc. All they now need to do is just write a basic test case for the functionality they added in the sprint and then potentially this can be added into hudson for continuous  integration. This was interesting and requires a blog post to document the classes I extended. However this post is more about the next steps. This also would be a great help for the testing team to amass regression suite written by the developer itself, which if done properly would be of the highest quality.</p>
<p>So the next step was to make a pear package out of it so that other projects could extend out of it and also to free the developer of the include path hell that php offers and as part of the exercise, I ran my code past php code sniffer. However good the tool is, its lacking on part of documentation (or atleast i couldn&#8217;t find much) and its obscure error messages only meant that I would have to dig into the code to find out what exactly it was looking for. So here are some of them of the obscure ones:</p>
<pre class="brush: bash; title: ; notranslate">
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AND 0 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 2 | ERROR | Missing file doc comment
 2 | ERROR | Missing class doc comment
--------------------------------------------------------------------------------
</pre>
<p>There isn&#8217;t any documentation that points out what it actually means with file document and class document. It turns out that it needs documentation about the class as well as the class, usually the same if there is only one level. Here is what I put in my class file to satisfy that.</p>
<pre class="brush: php; title: ; notranslate">
/**
* IPC_Test_Config
*
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@lalaland.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
/**
* IPC_Test_Config
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@lalaland.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
</pre>
<p>Here&#8217;s the next one:</p>
<pre class="brush: bash; title: ; notranslate">
--------------------------------------------------------------------------------
FOUND 0 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 10 | WARNING | PHP version not specified
--------------------------------------------------------------------------------
</pre>
<p>Now typically you would expect another @tag but its just <code>* PHP version 5</code> that you need to add. This is what the final version looks like:</p>
<pre class="brush: php; title: ; notranslate">
/**
* IPC_Test_Config
*
* PHP version 5
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@ipcmedia.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
/**
* IPC_Test_Config
*
* @category Testing
* @package  IPC.Test
* @author   Rajat Pandit &lt;rajat_pandit@ipcmedia.com&gt;
* @license  http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link     http://ipcmedia.com
*/
class IPC_Test_Config
</pre>
<p>I hope this post if useful for anyone who wants to use a code sniffer to ensure that the quality of code is kept to its highest.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/10/01/php-code-sniffer-and-common-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling HTTPS support in curl installed through MacPorts on OSX</title>
		<link>http://blog.rajatpandit.com/2009/03/31/enabling-https-support-in-curl-installed-through-macports-on-osx/</link>
		<comments>http://blog.rajatpandit.com/2009/03/31/enabling-https-support-in-curl-installed-through-macports-on-osx/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 22:27:40 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Clean]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[variants]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=250</guid>
		<description><![CDATA[While doing development just noticed that if you have installed php with curl support using macports it does&#8217;nt install ssl support in curl by default which is quite frustrating. Especially...]]></description>
			<content:encoded><![CDATA[<p>While doing development just noticed that if you have installed php with curl support using macports it does&#8217;nt install ssl support in curl by default which is quite frustrating. Especially I just spent 30mins of my life trying to debugging what had gone wrong.</p>
<p>This is what you would get if you have a similar problem:</p>
<pre class="brush: bash; title: ; notranslate">
% curl -k https://www.yahoo.com
curl: (1) Protocol https not supported or disabled in libcurl
</pre>
<p>The problem is that you would usually have something that depends on curl so you cant install the version of curl with its variant straightaway, so you will first need to remove the dependent first, then remove curl and clean up the install and then finally install curl with its ssl variant followed by its dependents.</p>
<p>The steps are something like this:</p>
<pre class="brush: bash; title: ; notranslate">
busybox:web rp$ sudo port uninstall curl @7.19.3_0 curl @7.19.3_0+ssl
---&gt;  Unable to uninstall curl 7.19.3_0, the following ports depend on it:
---&gt;  	php5
Error: port uninstall failed: Please uninstall the ports that depend on curl first.
busybox:web rp$ sudo port uninstall curl @7.19.3_0 curl @7.19.3_0+ssl
busybox:web rp$ sudo port uninstall php5
---&gt;  Deactivating php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
---&gt;  Uninstalling php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
busybox:web rp$ sudo port uninstall curl @7.19.3_0 curl @7.19.3_0+ssl
---&gt;  Deactivating curl @7.19.3_0
---&gt;  Uninstalling curl @7.19.3_0
---&gt;  Uninstalling curl @7.19.3_0+ssl
busybox:web rp$ sudo port install php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
Error: Requested variants do not match original selection.
Please perform 'port clean curl' or specify the force option.
Error: The following dependencies failed to build: curl
Error: Status 1 encountered during processing.
busybox:web rp$ sudo port clean curl
---&gt;  Cleaning curl
busybox:web rp$ sudo port clean php5
---&gt;  Cleaning php5
busybox:web rp$ sudo port clean php5
---&gt;  Cleaning php5
busybox:web rp$ sudo port clean curl
---&gt;  Cleaning curl
busybox:web rp$ sudo port clean php5
busybox:web rp$ sudo port install curl +ssl
---&gt;  Fetching curl
---&gt;  Verifying checksum(s) for curl
---&gt;  Extracting curl
---&gt;  Configuring curl
---&gt;  Building curl
---&gt;  Staging curl into destroot
---&gt;  Installing curl @7.19.3_0+ssl
---&gt;  Activating curl @7.19.3_0+ssl
---&gt;  Cleaning curl
busybox:web rp$ sudo port install php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
---&gt;  Fetching php5
---&gt;  Verifying checksum(s) for php5
---&gt;  Extracting php5
---&gt;  Applying patches to php5
---&gt;  Configuring php5
---&gt;  Building php5
---&gt;  Staging php5 into destroot
Warning: php5 requests to install files outside the common directory structure!
---&gt;  Installing php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite

If this is your first install, you might want
cd /opt/local/apache2/modules
/opt/local/apache2/bin/apxs -a -e -n &quot;php5&quot; libphp5.so

* copy  /opt/local/etc/php.ini-dist to  /opt/local/etc/php.ini
---&gt;  Activating php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
---&gt;  Cleaning php5
</pre>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/03/31/enabling-https-support-in-curl-installed-through-macports-on-osx/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Creating clean SEO urls in symfony</title>
		<link>http://blog.rajatpandit.com/2008/06/18/creating-clean-seo-urls-in-symfony/</link>
		<comments>http://blog.rajatpandit.com/2008/06/18/creating-clean-seo-urls-in-symfony/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 12:22:56 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Clean]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[routing]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[YML]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=26</guid>
		<description><![CDATA[Being the symfony fan that I am, I have decided to start documenting some of the features I think are quite neat in the framework. So starting today, here&#8217;s a...]]></description>
			<content:encoded><![CDATA[<p>Being the <a href="http://www.symfony-project.org/">symfony</a> fan that I am, I have decided to start documenting some of the features I think are quite neat in the framework. So starting today, here&#8217;s a quick quite to writing a Search Engine Optimized URL.<br />
So I am working on a project where users will be posting university details and I wanted the university names to appear on the url instead of the id. The problem with ID&#8217;s is it gives too much information about the application and if not carefully design can lead to data being exposed which the development might have not intented do.</p>
<p>So here&#8217;s the url that I was looking for. </p>
<pre class="brush: xml; title: ; notranslate">

http://testsite.rajatpandit.com/university/Indian_institute_of_management_ahemdabad.html
</pre>
<p>I got to the point where I had functional code which gave me URLs like these:</p>
<pre class="brush: xml; title: ; notranslate">

http://testsite.rajatpandit.com/university/id/1
</pre>
<p>These are the steps to convert the URLs are humanly understandable.<br />
Step 1:<br />
Add additional field to the university table to store the modified name. So  update the schema to addt the additional field.<br />
[yml]<br />
university:<br />
    _attribute: {phpName: University}<br />
    id: {type: integer, required: true, primaryKey: true, autoincrement: true}<br />
    name: varchar(256)<br />
    stripped_name: varchar(256)<br />
    website: varchar(256)<br />
    country: varchar(2)<br />
    city: varchar(256)<br />
    body: longvarchar<br />
    approved: boolean<br />
    created_at:<br />
    updated_at:<br />
[/yml]</p>
<p>Obviously  you would need to do the regular to regenerate the models.</p>
<pre class="brush: bash; title: ; notranslate">
#symfony propel-build-model
#symfony propel-build-sql
#symfony propel-insert-sql
</pre>
<p>or do it all in one easy step.</p>
<pre class="brush: bash; title: ; notranslate">
#symfony propel-build-all
</pre>
<p>Step 2:<br />
Now modify the model to update the new column (stripped_name) every time the standard <code>setName($v)</code> is called. For that we need to have a helper function that does this. Here&#8217;s the code I used, you can use your own version.</p>
<pre class="brush: php; title: ; notranslate">
function stripText($text) {
  $text = strtolower($text);
  $text = preg_replace('/\W/', ' ', $text);
  $text = preg_replace('/\ +/', '_', $text);
  $text = preg_replace('/\-$/', '', $text);
  $text = preg_replace('/^\-/', '', $text);
  return $text;
}
</pre>
<p>I create a new file called <code>CustomHelper.php</code> and store in under <code>lib/helper/</code> and then update the model class for <code>University</code> to override the function <code>setName($v)</code> with the following function.</p>
<pre class="brush: php; title: ; notranslate">
public function setName($v)
  {
    include_once('lib/helper/CustomHelper.php');
    parent::setName($v);
    $this-&gt;setStrippedName(stripText($v));
  }
</pre>
<p>That will ensure that the new column <code>stripped_name</code> gets updated.</p>
<p>Step 3:<br />
Update  your php template where you create the links to the following code.</p>
<pre class="brush: php; title: ; notranslate">
&lt;ul&gt;
  &lt;?php foreach($universities as $university): ?&gt;
    &lt;li&gt;
      &lt;?php echo link_to($university-&gt;getName(), '@university_display?stripped_name=' . stripText($university-&gt;getName())); ?&gt;
    &lt;/li&gt;
  &lt;?php endforeach; ?&gt;
&lt;/ul&gt;
</pre>
<p>and update the routing.yml to match the routing name used.</p>
<p>[yml]<br />
article_display:<br />
  url: /article/:stripped_title.html<br />
  param: {module: home, action: article}<br />
[/yml]<br />
The routing rule reads out like this,<br />
When you see the url containing /article/&lt;something&gt;.html redirect it to module: home to its action article and assign a request parameter &lt;stripped_html&gt; to  &lt;something&gt;.</p>
<p>and that&#8217;s all you need to do to get your urls look all nice and clean.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2008/06/18/creating-clean-seo-urls-in-symfony/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

