<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Robert Radošić</title>
    <description>The latest articles on Forem by Robert Radošić (@rradosic).</description>
    <link>https://forem.com/rradosic</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F584719%2F5f31cef6-49b9-428e-a7e6-9a2c4e1ebd0e.png</url>
      <title>Forem: Robert Radošić</title>
      <link>https://forem.com/rradosic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rradosic"/>
    <language>en</language>
    <item>
      <title>Setting up Jetbrains' Remote Development For WSL</title>
      <dc:creator>Robert Radošić</dc:creator>
      <pubDate>Mon, 03 Jan 2022 19:34:40 +0000</pubDate>
      <link>https://forem.com/bornfightcompany/setting-up-jetbrains-remote-development-for-wsl-1ek9</link>
      <guid>https://forem.com/bornfightcompany/setting-up-jetbrains-remote-development-for-wsl-1ek9</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;JetBrains family of IDEs recently got an update that introduced remote development features to almost all of their editors, albeit in a beta state. As claimed by JetBrains , remote development allows you, among other things, to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Connect to remote environments from anywhere in seconds&lt;/li&gt;
&lt;li&gt;Secure sensitive code on a remote server&lt;/li&gt;
&lt;li&gt;Introduce your team to cloud dev environments&lt;/li&gt;
&lt;li&gt;Streamline onboarding and tech interviews&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;But, what this finally enables is frictionless development with WSL on Windows machines. Anyone that has used Jetbrains' IDEs with WSL knows about indexing problems, git issues etc. With remote development all of these go away since all that is done on the actual WSL system and presented to you on the Windows side with the new JetBrains Client. &lt;/p&gt;

&lt;p&gt;Setting up remote development is easy and I'm gonna show you how...&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Windows Pro or greater&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install" rel="noopener noreferrer"&gt;WSL distro&lt;/a&gt; with SSH server enabled&lt;/li&gt;
&lt;li&gt;A JetBrains IDE version 2021.3 or greater (PHPStorm in this case)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setting up
&lt;/h2&gt;

&lt;p&gt;As I said previously, if you have all of the requirements satisfied setting up the project is really easy.&lt;br&gt;
When you open up your editor you're going to be presented with a project selection screen as usual but with a new remote development option&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2gyjyi0szbysafz9phj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2gyjyi0szbysafz9phj.png" alt="Project selection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, select this new option and let's continue. You are going to be asked your SSH username and server address. The address is "localhost" in case of WSL and the username is the one you chose during installation. &lt;br&gt;
After that it's time to select your IDE, select whichever one you're using and select the folder of your project.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: If you're having problems with IDE backend installation you can use "other options" and upload the installer file manually.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When everything is finished the JetBrains Client will launch and you are ready to start developing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things to look out for
&lt;/h2&gt;

&lt;p&gt;As this feature is still in beta some issues are to be expected. For example the IDE backend installation will fail in some cases but there is a manual workaround. Also, database tools have some weird issues, as well as the occasional UI glitch. Other than that, once it's out of beta it's definitely going to be the tool of choice when working with remote machines.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>linux</category>
      <category>tutorial</category>
      <category>engineeringmonday</category>
    </item>
    <item>
      <title>Integrating with the Erste Banking API</title>
      <dc:creator>Robert Radošić</dc:creator>
      <pubDate>Mon, 26 Jul 2021 13:40:49 +0000</pubDate>
      <link>https://forem.com/bornfightcompany/integrating-with-the-erste-banking-api-4gbe</link>
      <guid>https://forem.com/bornfightcompany/integrating-with-the-erste-banking-api-4gbe</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;As a part of a larger project, we had to integrate with the Erste PSD2 API. Although it's mostly your standard OAuth flow, there are a few "gotchas" along the way. This post will guide you to getting authenticated and pulling transactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Developer Portal
&lt;/h2&gt;

&lt;p&gt;Before you can start writing any code, you will need an Erste developer account. You can open one on the &lt;a href="https://developers.erstegroup.com/"&gt;Erste developers portal&lt;/a&gt; where you will be able to choose the branch of the bank you will be integrating with and which of the APIs you will be using. &lt;strong&gt;Take note that the only API you can use without certification is the Corporate API&lt;/strong&gt;. Luckily this was exactly the one we needed and didn't have to go through the certification process.&lt;/p&gt;

&lt;p&gt;Among many options that are available on the portal dashboard, the only three that you are going to need to get started are OAuth settings, credentials, and the certificates section. &lt;/p&gt;

&lt;p&gt;In the OAuth settings, you are going to set the callback URI, this is the URI to which the authorization code is going to be sent. If you don't have a local server that can accept HTTP requests, you can use something like &lt;a href="https://requestbin.com"&gt;RequestBin&lt;/a&gt; to output the request and get the authorization code.&lt;/p&gt;

&lt;p&gt;In the certificates section, you will find the public and private keys which you can download and install to your devices' CA store.&lt;/p&gt;

&lt;h2&gt;
  
  
  Calling API endpoints
&lt;/h2&gt;

&lt;p&gt;So, once we have the certificates installed and the callback URI setup, we can start calling the Erste API. &lt;/p&gt;

&lt;h3&gt;
  
  
  Consent ID
&lt;/h3&gt;

&lt;p&gt;The first endpoint that we are going to call is the /consents API which is going to return our consent ID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="se"&gt;\&lt;/span&gt;
 https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/netapi/consents &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'Content-Type: application/json'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'X-Request-ID: 4774477a-0508-4293-be86-6fca6f67adda'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'psu-ip-address: 127.0.0.1'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'web-api-key: WEB_API_KEY'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{
  "access": {
    "accounts": [],
    "balances": [],
    "transactions": []
  },
  "recurringIndicator": false,
  "validUntil": "2019-06-30",
  "frequencyPerDay": 4,
  "combinedServiceIndicator": false
}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the WEB_API_KEY is the API key in your developer dashboard.&lt;br&gt;
The response will return the consent ID, save it somewhere as it's going to be needed in other requests.&lt;/p&gt;
&lt;h3&gt;
  
  
  OAuth URL
&lt;/h3&gt;

&lt;p&gt;After we have obtained the consent token, we have to visit the URL with the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1netapi/auth
    ?redirect_uri=REDIRECT_URI
    &amp;amp;client_id=CLIENT_ID
    &amp;amp;response_type=code
    &amp;amp;access_type=offline
    &amp;amp;state=loremipsum
    &amp;amp;code_challenge=loremipsum
    &amp;amp;code_challenge_method=S256
    &amp;amp;scope=AIS:CONSENT_ID%20openid%20offline_access
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the variables are following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;REDIRECT_URI - the URI you put as the callback in the OAuth setting&lt;/li&gt;
&lt;li&gt;CLIENT_ID - client ID from your dashboard&lt;/li&gt;
&lt;li&gt;CONSENT_ID - consent ID from the previous request
If you put the right details in the URL you will be greeted with an OAuth mocking tool where you can choose what type of user you want to mock, and what access you are going to give for their accounts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Authorization code
&lt;/h3&gt;

&lt;p&gt;Once you select all the options in the OAuth mocking tool you will be redirected to the URI you put in the OAuth setting. If you are using RequestBin you can now go through the request and get the authorization code from the request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bearer token
&lt;/h3&gt;

&lt;p&gt;At this point, once we have obtained the authorization code and the consent token, we can finally call the /token endpoint and receive the Bearer token which will be used to get transactions, accounts, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="se"&gt;\&lt;/span&gt;
  https://webapi.developers.erstegroup.com/api/ebc/sandbox/v1/netapi/token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s1"&gt;'Content-Type: application/x-www-form-urlencoded'&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'redirect_uri=REDIRECT_URI&amp;amp;client_id=CLIENT_ID&amp;amp;client_secret=CLIENT_SECRET&amp;amp;grant_type=authorization_code&amp;amp;code_verifier=loremipsum&amp;amp;code=AUTHORIZATION_CODE'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the variables are following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;REDIRECT_URI - the URI you put as the callback in the OAuth setting&lt;/li&gt;
&lt;li&gt;CLIENT_ID - client ID from your dashboard&lt;/li&gt;
&lt;li&gt;CLIENT_SECRET - client secret from your dashboard&lt;/li&gt;
&lt;li&gt;AUTHORIZATION_CODE - authorization code from the previous request&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Calling other endpoints
&lt;/h2&gt;

&lt;p&gt;Once you have the Bearer token you can use standard Bearer auth in the header of your requests. With this token, you can pull transactions and accounts from the sandbox. To go to production, the requirements will vary from country to country. The most common procedure will involve giving your VAT number and the SSL cert for the domain your app will be using.&lt;/p&gt;

&lt;p&gt;If you are going to be integrating with the Croatian branch of the Erste bank using PHP take a look at our &lt;a href="https://github.com/bornfight/erste-bank-client-php"&gt;in-house library&lt;/a&gt; to help you get started.&lt;/p&gt;

</description>
      <category>php</category>
      <category>api</category>
      <category>webdev</category>
      <category>engineeringmonday</category>
    </item>
    <item>
      <title>Refactoring type annotations to PHP 7.4 type declarations with Rector</title>
      <dc:creator>Robert Radošić</dc:creator>
      <pubDate>Mon, 08 Mar 2021 14:11:35 +0000</pubDate>
      <link>https://forem.com/bornfightcompany/refactoring-type-annotations-to-php-7-4-type-declarations-with-rector-50a4</link>
      <guid>https://forem.com/bornfightcompany/refactoring-type-annotations-to-php-7-4-type-declarations-with-rector-50a4</guid>
      <description>&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;So, you have an older PHP project that uses type hinting via annotations and you would like to move away from those ugly annotations to nice inline type declarations. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;From this:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SomeClass&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
    * @var string
    */&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nv"&gt;$someProperty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;To this:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SomeClass&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$someProperty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sure, you could do it manually but depending on the size of the project this could take anywhere from a day to a couple of weeks. &lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;Well, worry not, this is where &lt;a href="https://github.com/rectorphp/rector"&gt;Rector&lt;/a&gt; comes in. Rector is a "tool for automated refactoring" that will make changes in your code based on pre-defined rules. One of those &lt;a href="https://github.com/rectorphp/rector/blob/master/docs/rector_rules_overview.md"&gt;many rules&lt;/a&gt; will help us to automatically move type declarations from annotations to inline declarations and that rule is called TypedPropertyRector. So now that we know what Rector is and what rule to use, how do we use it?&lt;/p&gt;

&lt;p&gt;First of all install Rector using composer&lt;br&gt;
&lt;code&gt;composer require rector/rector --dev&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Next, use the init command to create the rector.php config file&lt;br&gt;
&lt;code&gt;vendor/bin/rector init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now it's time to modify the config file to suit our use case&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="c1"&gt;//rector.php&lt;/span&gt;

&lt;span class="k"&gt;declare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strict_types&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Rector\Php74\Rector\Property\TypedPropertyRector&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;ContainerConfigurator&lt;/span&gt; &lt;span class="nv"&gt;$containerConfigurator&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$services&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$containerConfigurator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;services&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$services&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TypedPropertyRector&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you can either run Rector to process your files in the src directory&lt;br&gt;
&lt;code&gt;vendor/bin/rector process src&lt;/code&gt; or do a dry run to catch any errors that might pop up beforehand &lt;code&gt;vendor/bin/rector process src --dry-run&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Rector is an amazing tool that will let you do all sorts of improvements on your code and automate a lot of work when migrating to other PHP versions. It's also not a bad idea to consider using it as a part of your CI pipeline for automated code refactoring or even automated code review.&lt;/p&gt;

</description>
      <category>php</category>
      <category>refactoring</category>
      <category>webdev</category>
      <category>engineeringmonday</category>
    </item>
  </channel>
</rss>
