{"action":"closed","issue":{"url":"https://api.github.com/repos/padraic/mockery/issues/623","repository_url":"https://api.github.com/repos/padraic/mockery","labels_url":"https://api.github.com/repos/padraic/mockery/issues/623/labels{/name}","comments_url":"https://api.github.com/repos/padraic/mockery/issues/623/comments","events_url":"https://api.github.com/repos/padraic/mockery/issues/623/events","html_url":"https://github.com/padraic/mockery/issues/623","id":178270511,"number":623,"title":"Mocking methods with scalar type hinting and optional parameters fails with PHP 7.1","user":{"login":"letr0n","id":7405227,"avatar_url":"https://avatars.githubusercontent.com/u/7405227?v=3","gravatar_id":"","url":"https://api.github.com/users/letr0n","html_url":"https://github.com/letr0n","followers_url":"https://api.github.com/users/letr0n/followers","following_url":"https://api.github.com/users/letr0n/following{/other_user}","gists_url":"https://api.github.com/users/letr0n/gists{/gist_id}","starred_url":"https://api.github.com/users/letr0n/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/letr0n/subscriptions","organizations_url":"https://api.github.com/users/letr0n/orgs","repos_url":"https://api.github.com/users/letr0n/repos","events_url":"https://api.github.com/users/letr0n/events{/privacy}","received_events_url":"https://api.github.com/users/letr0n/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-09-21T07:42:34Z","updated_at":"2016-10-12T08:47:59Z","closed_at":"2016-10-12T08:47:59Z","body":"Hi,\r\n\r\nMocking methods that use scalar type hints will fail when using PHP 7.1 if the parameter is optional:\r\n\r\n```\r\npublic function foo(string $foo = null)\r\n{\r\n\r\n}\r\n```\r\n\r\nIt produces a `ParseError`:\r\n\r\n```\r\nParseError: syntax error, unexpected '?', expecting identifier (T_STRING)\r\n```\r\n\r\nThis is because [ReflectionParameter::getType()](https://github.com/padraic/mockery/blob/master/library/Mockery/Generator/Parameter.php#L77) prepends the type with a question mark if the parameter is nullable in PHP 7.1.\r\n\r\nI fixed it by changing [MethodDefinitionPass.php line 114](https://github.com/padraic/mockery/blob/master/library/Mockery/Generator/StringManipulation/Pass/MethodDefinitionPass.php#L114) from \r\n\r\n```\r\n$typeHint = trim($param->getTypeHintAsString());\r\n```\r\n\r\nto\r\n\r\n```\r\n$typeHint = ltrim(trim($param->getTypeHintAsString()), '?');\r\n```"}}
{"actor":{"display_login":"davedevelopment"}}