Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version is mandatory at vCard 4.0 #128

Conversation

helveticadomes
Copy link

version is mandatory and at vCard 4.0 and it has to be on the line direct after the Begin Property

Copy link
Owner

@jeroendesloovere jeroendesloovere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a Version Property/Parameter.
Maby you can find a way:

to make it "required"?
to place it as the first property?

@helveticadomes
Copy link
Author

helveticadomes commented Jun 20, 2018

The vCard need to start with:

BEGIN:VCARD
VERSION:4.0  
here comes the first fields

now the vCard begins with

BEGIN:VCARD  
here comes the first fields

Defined by the Specifications:
https://tools.ietf.org/html/rfc6350#section-6.7.9

Special notes: This property MUST be present in the vCard object,
and it must appear immediately after BEGIN:VCARD. The value MUST
be "4.0" if the vCard corresponds to this specification. Note
that earlier versions of vCard allowed this property to be placed
anywhere in the vCard object, or even to be absent.

@helveticadomes helveticadomes changed the title version is mandatory and at vCard 4.0 version is mandatory at vCard 4.0 Jun 20, 2018
@jeroendesloovere
Copy link
Owner

jeroendesloovere commented Jun 20, 2018

@helveticadomes, I do understand what the purpose is.

I'm just not sure if we should go "your solution" or "need to use the already available"

… after the Begin Property

Use the Version Property instead of static
@helveticadomes
Copy link
Author

helveticadomes commented Jun 21, 2018

As Requested i update my pullrequest:
it does now use the Version Formatter/Parser instead of the static Version.
It also make it mandatory and move the Version Property to the first line after begin.
after a few trys i also be able to pass the Travis checks

src/VCard.php Outdated
}

public function getParameters(string $filterByPropertyParameterClass = null): array
{
if ($filterByPropertyParameterClass === null) {

$array = $this->parameters;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace your entire "additions" here by an array_map().
In that new function you could check "return ($class instanceof Version) ? -1 : +1".
Using such an easy way we move our "Version" to the frond of the array by using comparisons.

Another (but bigger) addition to this solution could be to add a $priority value to each and every Property.

Copy link
Author

@helveticadomes helveticadomes Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure. with help of a similar addition i can solve #113 => https://github.com/helveticadomes/vcard/blob/feature-fix-name-property/src/VCard.php
Lines 167-190
Pullrequest not quite finished yet

@@ -12,6 +12,7 @@
public const CONTENT_TYPE = 'text/vcard';
public const FILE_EXTENSION = 'vcf';
public const VCARD_BEGIN = 'BEGIN:VCARD';
//public const VCARD_VERSION = 'VERSION:4.0';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed

@@ -21,6 +22,7 @@ public function getContent(array $vCards): string
/** @var VCard $vCard */
foreach ($vCards as $vCard) {
$string .= self::VCARD_BEGIN . "\r\n";
//$string .= self::VCARD_VERSION . "\r\n";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed

src/VCard.php Outdated
@@ -130,12 +132,24 @@ private function addPropertyParameter(PropertyParameterInterface $propertyParame

public function getKind(): Kind
{
return $this->getParameters(Kind::class)[0];
$kind = $this->getParameters(Kind::class);
return reset($kind);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to one line

Copy link
Author

@helveticadomes helveticadomes Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No => that would lead to:

Notice: Only variables should be passed by reference in ..\vendor\jeroendesloovere\vcard\src\VCard.php on line 136

at least if it is done like that:

return reset($this->getParameters(Kind::class));

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, probably return reset($kind = $this->getParameters(Kind::class)); will work then.

But I suggest you leave it like that. Just "add an empty rule above the return statement".

Copy link
Author

@helveticadomes helveticadomes Jun 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately your suggested code doesn't work either
why empty rule? because of $this->add($kind ?? Kind::individual()); inside constructor it could not be empty

Copy link
Owner

@jeroendesloovere jeroendesloovere Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good practice to add an empty line above a return statement like this:

$kind = $this->getParameters(Kind::class);

return reset($kind);

and not like this:

$kind = $this->getParameters(Kind::class);
return reset($kind); 

@melroy89
Copy link

Please, merge this. The version number is required in v4:
https://tools.ietf.org/html/rfc6350#page-48

I think helveticadomes did wonderful work.

@melroy89
Copy link

Special notes:  This property MUST be present in the vCard object,
      and it must appear immediately after BEGIN:VCARD.  The value MUST
      be "4.0" if the vCard corresponds to this specification.

@jeroendesloovere jeroendesloovere merged commit 6346d51 into jeroendesloovere:2.0.0-dev Mar 2, 2019
@melroy89
Copy link

melroy89 commented Mar 2, 2019

@jeroendesloovere Note: Since I'm validating the actual context. This merge should lead to a UT failures now. Which is good! Since I wrote a good unit testers that ACTUALLY checks the content as well 👍

Nevertheless, this does require some change in the UT to fix it again, see:
https://travis-ci.org/jeroendesloovere/vcard/jobs/500787051

Like this line:
https://github.com/jeroendesloovere/vcard/blob/2.0.0-dev/tests/VCardTest.php#L249
And line:
https://github.com/jeroendesloovere/vcard/blob/2.0.0-dev/tests/VCardTest.php#L271

Likely needs to be extended with this version 4.0 :)

@melroy89
Copy link

melroy89 commented Mar 2, 2019

@jeroendesloovere I will fix the failing test! However, I found another bug in the version parser (or lack of parsing of the version I would say). I will try to fix that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants